Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| """ | |
| Fetch and vendor Clash Royale card data into this repo. | |
| Why: | |
| - RoyaleAPI maintains a public static dataset (no auth key) which is stable and reproducible. | |
| - We vendor the raw JSON so the HF Space / OpenEnv environment does NOT depend on network. | |
| Sources: | |
| - Cards list: https://royaleapi.github.io/cr-api-data/json/cards.json | |
| - Card stats: https://royaleapi.github.io/cr-api-data/json/cards_stats.json | |
| Refs: | |
| - RoyaleAPI static data index: https://royaleapi.github.io/cr-api-data/ | |
| """ | |
| import json | |
| from pathlib import Path | |
| import requests | |
| CARDS_URL = "https://royaleapi.github.io/cr-api-data/json/cards.json" | |
| STATS_URL = "https://royaleapi.github.io/cr-api-data/json/cards_stats.json" | |
| def _write_json(path: Path, obj) -> None: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(obj, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") | |
| def main() -> int: | |
| root = Path(__file__).resolve().parents[1] | |
| data_dir = root / "data" | |
| cards = requests.get(CARDS_URL, timeout=60).json() | |
| stats = requests.get(STATS_URL, timeout=60).json() | |
| _write_json(data_dir / "cards_full.json", cards) | |
| _write_json(data_dir / "cards_stats_full.json", stats) | |
| print("wrote:", data_dir / "cards_full.json") | |
| print("wrote:", data_dir / "cards_stats_full.json") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |