diff --git a/web/fetch_pro_matches.py b/web/fetch_pro_matches.py index 2cb4098..e6f7ac1 100644 --- a/web/fetch_pro_matches.py +++ b/web/fetch_pro_matches.py @@ -666,14 +666,55 @@ def main() -> None: player_source = "proPlayers" _log("loading pro players ...") - try: + pro_index: dict[int, dict] = {} + if args.all_pros and not player_ids_raw: pro_index = fetch_pro_index() - except SystemExit as exc: - # Watchlist runs can proceed without /proPlayers when OpenDota is 429'd. - if args.all_pros and not player_ids_raw: - raise - _log(f" warn: {exc}; continuing with watchlist/cli names only") - pro_index = {} + else: + # Fail-fast: watchlist runs do not need /proPlayers to refresh matches. + try: + raw = http_json(f"{OPENDOTA}/proPlayers", retries=0) + except ( + urllib.error.HTTPError, + urllib.error.URLError, + TimeoutError, + json.JSONDecodeError, + OSError, + ) as exc: + _log(f" warn: proPlayers unavailable ({exc}); watchlist names only") + raw = None + if isinstance(raw, list): + for row in raw: + if not isinstance(row, dict): + continue + try: + aid = int(row.get("account_id") or 0) + except (TypeError, ValueError): + continue + if aid <= 0: + continue + name = row.get("name") + if isinstance(name, str): + name = name.strip() or None + else: + name = None + team_tag = row.get("team_tag") + if isinstance(team_tag, str): + team_tag = team_tag.strip() or None + else: + team_tag = None + team_name = row.get("team_name") + if isinstance(team_name, str): + team_name = team_name.strip() or None + else: + team_name = None + pro_index[aid] = { + "account_id": aid, + "name": name, + "team_tag": team_tag, + "team_name": team_name, + "country_code": row.get("country_code"), + "last_match_time": row.get("last_match_time"), + } _log(f" {len(pro_index)} registered pros") player_ids = parse_pro_filter(args.players, pro_index)