Files
Otkritiebot/session_bot/storage.py
Verum 02afbd23ec
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 34s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 13s
123
2026-04-02 18:04:04 +07:00

21 lines
592 B
Python

from __future__ import annotations
import json
from pathlib import Path
class JsonStateStorage:
def __init__(self, path: Path) -> None:
self.path = path
def load(self) -> dict:
if not self.path.exists():
return {"actors": {}}
with self.path.open("r", encoding="utf-8") as file:
return json.load(file)
def save(self, payload: dict) -> None:
self.path.parent.mkdir(parents=True, exist_ok=True)
with self.path.open("w", encoding="utf-8") as file:
json.dump(payload, file, ensure_ascii=False, indent=2)