From a97a28de6f248c7dadb65121eeba62c890ec70b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AE=D1=80=D0=B8=D0=B9=20=D0=A7=D0=B5=D1=80=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE?= Date: Wed, 29 Oct 2025 14:23:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BE=20=D1=81?= =?UTF-8?q?=D0=B5=D0=B7=D0=BE=D0=BD=D1=83=20=D0=BD=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B.=20=D0=BE=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D1=80=D0=B0=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_data.py | 76 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/get_data.py b/get_data.py index 61c611b..be6176f 100644 --- a/get_data.py +++ b/get_data.py @@ -491,6 +491,8 @@ def classify_game_state_from_status(status_raw: str) -> str: return "finished" if status in ("", "notstarted", "draft"): return "upcoming" + # if status in ("scheduled"): + # return "scheduled" # всё остальное считаем лайвом return "live" @@ -1792,6 +1794,7 @@ def Standing_func( (comp.get("name") or "unknown_comp") .replace(" ", "_") .replace("|", "") + .replace("/", "") ) if item.get("standings"): @@ -1979,27 +1982,6 @@ def get_data_API( if phase == "live": # матч идёт → запускаем live_loop блокирующе - t = threading.Thread( - target=run_live_loop, - args=(league, season, game_id, lang, today_game["game"], stop_event), - daemon=False, - ) - t.start() - logger.info("[get_data_API] live thread spawned, waiting for it to finish") - - try: - t.join() - except KeyboardInterrupt: - logger.info( - "[get_data_API] KeyboardInterrupt while waiting live thread -> stop_event" - ) - stop_event.set() - t.join() - - logger.info("[get_data_API] live thread finished") - return "live_done" - - if phase == "upcoming": logger.info( f"Матч {game_id} сегодня, но ещё не начался (status={effective_status}). Подготовка pregame." ) @@ -2031,7 +2013,59 @@ def get_data_API( logger.exception( f"[get_data_API] ошибка при подготовке pregame для {game_id}: {e}" ) + t = threading.Thread( + target=run_live_loop, + args=(league, season, game_id, lang, today_game["game"], stop_event), + daemon=False, + ) + t.start() + logger.info("[get_data_API] live thread spawned, waiting for it to finish") + try: + t.join() + except KeyboardInterrupt: + logger.info( + "[get_data_API] KeyboardInterrupt while waiting live thread -> stop_event" + ) + stop_event.set() + t.join() + + logger.info("[get_data_API] live thread finished") + return "live_done" + + if phase == "upcoming": + + logger.info( + f"Матч {game_id} сегодня, но ещё не начался (status={effective_status}). Подготовка pregame." + ) + + # дергаем pregame только один раз за матч + if not _pregame_done_for_game.get(game_id): + try: + pregame_raw = fetch_api_data( + session, + "pregame", + host=HOST, + league=league, + season=season, + game_id=game_id, + lang=lang, + ) + + Pregame_data( + pregame_raw=pregame_raw, + game_stub=today_game["game"], + ) + + _pregame_done_for_game[game_id] = True + logger.info( + f"[get_data_API] pregame данные собраны для game_id={game_id}" + ) + + except Exception as e: + logger.exception( + f"[get_data_API] ошибка при подготовке pregame для {game_id}: {e}" + ) # матч сегодня, ждём старта return "upcoming"