Add weekly Blue Archive roster auto-refresh

This commit is contained in:
esef committed 2026-09-15 15:19:17 +03:00
1 parent 23b8c3722a
commit c8e3ab57cc
2 files changed
+30 -1

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
"""Refresh the bundled Blue Archive roster from the live ennead.cc API.
Loads the current ba_students.json, merges any characters that have been
released since the last run, and atomically writes the result back. Run weekly
via the discordbot-refresh systemd timer so fresh clones stay current without
depending on the live API at startup.
"""
import asyncio
import json
from pathlib import Path
from blue_archive.data import db, fetch_banners
OUT = Path(__file__).with_name("ba_students.json")
async def main() -> None:
db.load()
banners = await fetch_banners()
added = await db.merge_ennead(banners)
tmp = OUT.with_suffix(".json.tmp")
tmp.write_text(json.dumps(db.students, ensure_ascii=False), encoding="utf-8")
tmp.replace(OUT) # atomic swap so a reader never sees a partial file
print(f"refreshed {OUT.name}: {len(db.students)} students (+{added} new)")
if __name__ == "__main__":
asyncio.run(main())