diff --git a/get_data.py b/get_data.py index f1322b0..62f0b09 100644 --- a/get_data.py +++ b/get_data.py @@ -160,6 +160,8 @@ def start_offline_threads(season, game_id): URLS["game"].format(host=HOST, game_id=game_id, lang=LANG), 300, # опрашиваем раз в секунду/реже stop_event_offline, + False, + True, ), daemon=True, ), @@ -331,6 +333,7 @@ def get_data_from_API( sleep_time: float, stop_event: threading.Event, stop_when_live=False, + stop_after_success: bool = False, # 👈 новый флаг ): did_first_fetch = False while not stop_event.is_set(): @@ -370,6 +373,14 @@ def get_data_from_API( ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] results_q.put({"source": name, "ts": ts, "data": value}) logger.debug(f"[{ts}] name: {name}, status: {value.get('status', 'no-status')}") + ok_status = not ( + isinstance(value, dict) + and str(value.get("status", "")).lower() in ("error", "fail", "no-status") + ) + + if stop_after_success and ok_status: + logger.info(f"[{name}] got successful response → stopping thread (stop_after_success)") + return # сколько уже заняло # elapsed = time.time() - start