Files
poli0981andClaude Opus 5.5 11c38dba24 fix: the first Qodana findings
No behaviour changes; each is what the inspection asked, or the type
information it lacked.

Python (scripts/):
- `return (a, b)` -> `return a, b` (12, steam_client, store_items,
  backfill_discover).
- `log=print` parameters annotated `Callable[[str], None]`: PyCharm could
  not type the overloaded builtin as a default and called every log(...)
  "not callable" (10, budget, purge_unhealthy, refresh_anticheat,
  refresh_peaks).
- fetch_full()'s docstring names all its parameters.
- Nested helpers no longer shadow the loop variables of the function
  around them (purge_unhealthy judge(), update_reviews ask()).
- The leaderboards' bare `except:` catches what a reviews string can
  raise (AttributeError, TypeError, ValueError), not SystemExit and
  KeyboardInterrupt too.
- edit_game.py: unused `import json` dropped; mark_dead_games `[^\d]` ->
  `\D`; the DLC section regex loses a group around the whole pattern
  (only ever used with search()).

TypeScript / Svelte (web/):
- Two comma expressions written as statements (pipeline route's run
  dedupe, CandidateDialog's Reopen button).
- shouldIgnore() returns its last condition instead of if/return.
- Resource's constructor-only private fields are readonly.
- The admin mock seed says HOUR, not 1 * HOUR.

Rust (web/src-tauri/): `serde` dropped - nothing in the crate or in what
generate_context!() expands uses it (only `::serde_json` paths are
generated). serde_json stays, with a comment: Qodana calls it unused
too, but the generated code needs it and the crate does not compile
without it.

Checked: pytest 467, typecheck, vitest 747, knip, cargo test --lib.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:54:28 +07:00

84 lines
3.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Top online leaderboard."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from datetime import datetime, timezone
from core.budget import Deadline
from core.constants import STEAM_API_KEY, GAMES_DIR, TOP_ONLINE_LIMIT
from core.data_store import load_main, save_main, extract_appid
from core.fetcher import update_players_only
def _ppc(s):
c = s.replace(",","").strip()
return int(c) if c.isdigit() else 0
_TIERS = [(100000,"🔥 Mega"),(30000,"⭐ Hot"),(10000,"🟢 Healthy"),
(3000,"🟡 Stable"),(500,"🟠 Low"),(50,"🔴 Dying")]
def _tier(c):
for thresh, label in _TIERS:
if c >= thresh: return label
return "💀 Dead"
def _trend(cur, prev):
if prev == 0: return "🆕"
d = ((cur - prev) / prev) * 100
if d > 15: return f"📈+{d:.0f}%"
if d > 3: return f"↑+{d:.0f}%"
if d < -15: return f"📉{d:.0f}%"
if d < -3: return f"↓{d:.0f}%"
return "→"
_STAR_THRESHOLDS = [(95,"★★★★★"),(80,"★★★★☆"),(70,"★★★☆☆"),(50,"★★☆☆☆")]
def _stars(r):
try: p = int(r.split("%")[0])
except (AttributeError, TypeError, ValueError): return "—"
for thresh, s in _STAR_THRESHOLDS:
if p >= thresh: return s
return "★☆☆☆☆"
def main():
if not STEAM_API_KEY: print("No key."); sys.exit(1)
deadline = Deadline.from_env()
games = load_main()
online = [g for g in games if g.get("type_game","").lower()=="online"
and g.get("status","active")=="active"]
if not online: print("No online games."); sys.exit(1)
print(f"{len(online)} online games...")
prev = {}
for g in online:
aid = extract_appid(g.get("link",""))
if aid: prev[aid] = _ppc(g.get("current_players","0"))
update_players_only(games, deadline=deadline)
# Re-filter after update (status may have changed)
online = [g for g in games if g.get("type_game","").lower()=="online"
and g.get("status","active")=="active"]
online.sort(key=lambda g: _ppc(g.get("current_players","0")), reverse=True)
tp = sum(_ppc(g.get("current_players","0")) for g in online)
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
os.makedirs(GAMES_DIR, exist_ok=True)
with open(f"{GAMES_DIR}/top-online.md", "w", encoding="utf-8") as f:
f.write(f"# 🎮 Top Online – Live Leaderboard\n\n> {now} | {len(online)} games | {tp:,} players\n\n")
f.write("| # | Game | Players | Trend | Tier | Rating | Genre | AC | Peak | Link |\n")
f.write("|---|------|---------|-------|------|--------|-------|----|------|------|\n")
for rank, g in enumerate(online[:TOP_ONLINE_LIMIT], 1):
aid = extract_appid(g.get("link",""))
c = _ppc(g.get("current_players","0"))
n = g.get("name","?")
if len(n) > 40: n = n[:37] + "..."
ac = g.get("anti_cheat","-")
if g.get("is_kernel_ac") is True and ac != "-": ac += "🔴"
f.write(f"| {rank} | {n} | {g.get('current_players','N/A')} "
f"| {_trend(c,prev.get(aid,0))} | {_tier(c)} | {_stars(g.get('reviews','N/A'))} "
f"| {g.get('genre','N/A')} | {ac} | {g.get('peak_today','N/A')} "
f"| [Steam]({g.get('link','#')}) |\n")
rest = online[TOP_ONLINE_LIMIT:]
if rest:
dead = sum(1 for g in rest if _ppc(g.get("current_players","0")) < 50)
f.write(f"\n*+{len(rest)} more ({dead} <50 players)*\n")
save_main(games)
print(f"✓ → {GAMES_DIR}/top-online.md")
if __name__ == "__main__": main()