Files

23 lines
672 B
Python

"""Управление состоянием (state.json в папке раздела)."""
import json
from .config import OUTPUT_DIR
def _state_file(section_slug: str) -> Path:
d = OUTPUT_DIR / section_slug
d.mkdir(parents=True, exist_ok=True)
return d / "state.json"
def load(section_slug: str) -> dict:
f = _state_file(section_slug)
if f.exists():
return json.loads(f.read_text(encoding="utf-8"))
return {"topics_done": {}, "pages_done": [], "file_index": 0, "topic_count": 0}
def save(section_slug: str, st: dict):
_state_file(section_slug).write_text(
json.dumps(st, ensure_ascii=False, indent=2), encoding="utf-8")