diff --git a/README.md b/README.md index a092e8b..ea64075 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ it started as a simple music bot and became a massive mess of features i actuall - deepseek api for the ai stuff - wavelink + lavalink (java) for music - psutil + lm-sensors for hardware stats -- runs as systemd services: `discordbot` and `lavalink` +- runs as systemd services: `discordbot`, `lavalink`, and a weekly `discordbot-refresh.timer` that auto-updates the Blue Archive roster ## commands diff --git a/blue_archive/refresh_roster.py b/blue_archive/refresh_roster.py new file mode 100644 index 0000000..ff56829 --- /dev/null +++ b/blue_archive/refresh_roster.py @@ -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())