Files
999/scripts/export_ogham_atlas.py
T

55 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Build assets/data/ogham_feda.json from scraped corpus + unified texts."""
from __future__ import annotations
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
CORPUS = ROOT / "oracle_enricher" / "data" / "sources" / "ogham_corpus.json"
UNIFIED = ROOT / "oracle_enricher" / "out" / "ogham_unify" / "unified.json"
CANON = ROOT / "oracle_enricher" / "data" / "traditions_canon.json"
OUT = ROOT / "assets" / "data" / "ogham_feda.json"
def main() -> None:
if not CORPUS.exists():
raise SystemExit("нет ogham_corpus.json")
corpus = json.loads(CORPUS.read_text(encoding="utf-8"))
unified = json.loads(UNIFIED.read_text(encoding="utf-8")) if UNIFIED.exists() else {}
canon = json.loads(CANON.read_text(encoding="utf-8"))
by_id = {s["id"]: s for s in canon["ogham"]["stations"]}
order = [s["id"] for s in canon["ogham"]["stations"]]
cards = []
for i, cid in enumerate(order, 1):
cc = corpus["cards"].get(cid, {"id": cid, "meanings": [], "name_en": cid, "tree_ru": ""})
st = by_id.get(cid, {})
uc = (unified.get("cards") or {}).get(cid) or (unified.get("cards") or {}).get(str(i)) or {}
umeaning = (uc.get("meaning") or "").strip()
cards.append(
{
"n": i,
"id": cid,
"name": st.get("name") or cc.get("name_en"),
"symbol": st.get("symbol", ""),
"lore": (uc.get("core") or st.get("lore") or ""),
"group": st.get("group", ""),
"meaning": umeaning,
"shadow": (uc.get("shadow") or "").strip(),
"meanings": [] if umeaning else cc.get("meanings") or [],
"pairs": [],
}
)
OUT.parent.mkdir(parents=True, exist_ok=True)
OUT.write_text(
json.dumps({"system": "ogham", "card_count": len(cards), "cards": cards}, ensure_ascii=False, indent=2)
+ "\n",
encoding="utf-8",
)
print("wrote", OUT, "n", len(cards))
if __name__ == "__main__":
main()