Spaces:
Sleeping
Sleeping
Update src/gametracker/grab_gt_stats.py
Browse files18 unmodified lines192021222324258 unmodified lines343536373839404142434446 unmodified lines9192939495969713 unmodified lines11111211311411511611718 unmodified linesGPU_AVAILABLE = False# ---- Config ----HOST = "149.202.87.35:27015"START = "-1w"OUT_DIR = Path("/tmp/")OUT_DIR.mkdir(parents=True, exist_ok=True)8 unmodified lines"""Base64-encode a player name for GameTracker URL."""return quote_plus(base64.b64encode(name.encode("utf-8")).decode("ascii"))def build_url(name: str) -> str:"""Build the GameTracker image URL for a specific player."""return ("https://cache.gametracker.com/images/graphs/player_time.php"f"?nameb64={b64_name(name)}&host={HOST}&start={START}")def download_image(url: str, out_path: Path) -> Path:46 unmodified lines# Main logic# ------------------------------def fetch_playtimes(admin_file_or_list=Path.cwd().parent / "data" / "admins.txt") -> dict[str, int]:"""Fetch playtimes for all admins via GameTracker (OCR).Accepts either:13 unmodified linesresults: dict[str, int] = {}for name in admins:url = build_url(name)img_path = OUT_DIR / f"{name}.png"try:download_image(url, img_path)18 unmodified lines19202122232425268 unmodified lines353637383940414243444546474849505146 unmodified lines989910010110210310413 unmodified lines11811912012112212312418 unmodified linesGPU_AVAILABLE = False# ---- Config ----HOST_PUBLIC = "149.202.87.35:27015"HOST_AFK = "149.202.87.35:27016"START = "-1w"OUT_DIR = Path("/tmp/")OUT_DIR.mkdir(parents=True, exist_ok=True)8 unmodified lines"""Base64-encode a player name for GameTracker URL."""return quote_plus(base64.b64encode(name.encode("utf-8")).decode("ascii"))def build_url(name: str, server_type: str = "public") -> str:"""Build the GameTracker image URL for a specific player."""if server_type.lower() == "public":host = HOST_PUBLICelif server_type.lower() == "afk":host = HOST_AFKelse:host = HOST_PUBLIC # Defaultreturn ("https://cache.gametracker.com/images/graphs/player_time.php"f"?nameb64={b64_name(name)}&host={host}&start={START}")def download_image(url: str, out_path: Path) -> Path:46 unmodified lines# Main logic# ------------------------------def fetch_playtimes(admin_file_or_list=Path.cwd().parent / "data" / "admins.txt", server_type: str = "public") -> dict[str, int]:"""Fetch playtimes for all admins via GameTracker (OCR).Accepts either:13 unmodified linesresults: dict[str, int] = {}for name in admins:url = build_url(name, server_type)img_path = OUT_DIR / f"{name}.png"try:download_image(url, img_path)
src/gametracker/grab_gt_stats.py+12-5