static_data
static_data
¶
Static game data (troops, spells, heroes, pets, equipment, leagues, ...).
The official API serves no static game data, so this module loads a JSON file in
the format published by the ClashKing project
(https://github.com/ClashKingInc/clashy.py, coc/static/static_data.json, MIT).
Nothing is bundled: pass a path, or call :meth:StaticData.download to fetch and
cache it (explicit opt-in network access).
Example::
from cocapi import StaticData
sd = StaticData.download() # cached at ~/.cocapi/static_data.json
sd.by_name("troops", "Barbarian")
sd.by_id("heroes", 28000000)
sd.names("equipment")
StaticData
¶
StaticData(data: dict[str, Any])
Name/ID lookups over a static game data JSON document.
Source code in cocapi/static_data.py
34 35 36 37 | |
load
classmethod
¶
load(path: str | Path | None = None) -> StaticData
Load from a local JSON file (default ~/.cocapi/static_data.json).
Source code in cocapi/static_data.py
39 40 41 42 43 44 | |
download
classmethod
¶
download(
path: str | Path | None = None,
url: str = DEFAULT_URL,
refresh: bool = False,
timeout: float = 60.0,
) -> StaticData
Download the data (unless already cached) and load it.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Where to cache the file (default
TYPE:
|
url
|
Source URL.
TYPE:
|
refresh
|
Re-download even if the cache file exists.
TYPE:
|
Source code in cocapi/static_data.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
by_name
¶
by_name(category: str, name: str) -> dict[str, Any] | None
Case-insensitive lookup by name.
Source code in cocapi/static_data.py
82 83 84 85 86 87 88 | |
max_level
¶
max_level(
category: str, name: str, townhall: int | None = None
) -> int | None
Highest level of an item (optionally limited by Town Hall level).
Source code in cocapi/static_data.py
113 114 115 116 117 118 119 120 121 122 123 124 125 | |