grants-rag / app /storage.py
michaellupo74's picture
feat: update ingest deadline parsing and add storage module
8e3c9fc
raw
history blame contribute delete
713 Bytes
# app/storage.py
from __future__ import annotations
from pathlib import Path
import json
from typing import Dict, Any
STATE_DIR = Path("data/user_state")
STATE_DIR.mkdir(parents=True, exist_ok=True)
def _file(user_id: str) -> Path:
return STATE_DIR / f"{user_id}.json"
def load_state(user_id: str) -> Dict[str, Any]:
p = _file(user_id)
if not p.exists():
return {"saved": [], "hidden": []}
try:
return json.loads(p.read_text(encoding="utf-8"))
except Exception:
return {"saved": [], "hidden": []}
def save_state(user_id: str, state: Dict[str, Any]) -> None:
p = _file(user_id)
p.write_text(json.dumps(state, ensure_ascii=False, indent=2), encoding="utf-8")