Spaces:
Sleeping
Sleeping
Update src/gametracker/grab_gt_stats.py
Browse files18 unmodified lines1920212222232425268 unmodified lines3536373738394041424344454647414849505146 unmodified lines98991009410110210310413 unmodified lines11811912011412112212312418 unmodified lines GPU_AVAILABLE = False
# ---- Config ----HOST = "149.202.87.35:27015"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) -> str: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_PUBLIC elif server_type.lower() == "afk": host = HOST_AFK else: host = HOST_PUBLIC # Default return ( "https://cache.gametracker.com/images/graphs/player_time.php" f"?nameb64={b64_name(name)}&host={HOST}&start={START}" 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]: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 lines
results: dict[str, int] = {} for name in admins: url = build_url(name) 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