File size: 1,415 Bytes
b0620f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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())