diff --git a/get_data.py b/get_data.py index f7b1ebe..47e1ae1 100644 --- a/get_data.py +++ b/get_data.py @@ -354,11 +354,11 @@ def merge_online_payloads( # нормализация/дедуп # plays = _dedup_plays(plays_raw) - game["result"]["plays"] = play_by_play.get("result", []) - game["result"]["scoreByPeriods"] = box_score["result"].get("scoreByPeriods", []) - game["result"]["fullScore"] = box_score["result"].get("fullScore", {}) - game["result"]["live_status"] = live_status["result"] - + # print(game) + game["plays"] = play_by_play.get("result", []) + game["scoreByPeriods"] = box_score["result"].get("scoreByPeriods", []) + game["fullScore"] = box_score["result"].get("fullScore", {}) + game["live_status"] = live_status["result"] merged: Dict[str, Any] = { "meta": { "generatedAt": _now_iso(), @@ -430,11 +430,17 @@ def ensure_merged_payload( } return merged + # 2) Онлайн-ветка — склеиваем так, как у тебя уже реализовано if box_score is not None or play_by_play is not None or live_status is not None: base_game = game_meta or {} - return merge_online_payloads(base_game, box_score, play_by_play, live_status) + out_path = Path("static") / "game.json" + with open(out_path, "r", encoding="utf-8") as file: + game = json.load(file) + base_game = game["result"] + # print(base_game) + return merge_online_payloads(base_game, box_score, play_by_play, live_status) # 2b) Fallback: если пришёл "game", но без plays/fullScore/scoreByPeriods — всё равно сохраним if game_or_merged: g = game_or_merged.get("result") or game_or_merged @@ -502,6 +508,7 @@ def Json_Team_Generation( # Имя файла # print(merged) + # merged = if who == "team1": for i in merged["result"]["teams"]: if i["teamNumber"] == 1: @@ -1642,6 +1649,10 @@ def is_game_online(league: str, game_id: str, lang: str) -> str: """ url = URL_GAME.format(host=HOST, league=league, game_id=game_id, lang=lang) data = fetch_json(url) + + out_path = Path("static") / "game.json" + atomic_write_json(out_path, data) + return extract_game_status(data) @@ -1722,7 +1733,7 @@ class OnlinePoller: if self._thread and self._thread.is_alive(): self._stop_event.set() self._thread.join(timeout=2) - self._log.info(f"Онлайн-поллер для игры {self.game_id} остановлен.") + # self._log.info(f"Онлайн-поллер для игры {self.game_id} остановлен.") self._thread = None try: self._session.close() @@ -1770,7 +1781,7 @@ class OnlinePoller: live_status=ls, game_meta={"id": self.game_id, "league": self.league}, ) - + # print(merged) # внешний коллбек, если задан if self._on_update: self._on_update(merged) @@ -1778,7 +1789,7 @@ class OnlinePoller: # твоя общая обработка + сохранение self._post.submit(merged) - self._log.debug( + logger.debug( "Обновления online: box-score(%s keys), pbp(%s keys), live-status(%s keys)", len(bs) if isinstance(bs, dict) else "—", len(pbp) if isinstance(pbp, dict) else "—", @@ -1819,7 +1830,8 @@ def monitor_game_loop( while not stop_event.is_set(): try: status = is_game_online(league, game_id, lang) - is_online = status in {"inprogress", "live", "online"} + # print(status) + is_online = status in {"scheduled", "online"} is_finished = status in {"resultconfirmed", "result"} if is_finished: diff --git a/visual.py b/visual.py index af5a047..e913f93 100644 --- a/visual.py +++ b/visual.py @@ -425,8 +425,8 @@ ip_check = read_match_id_json("match_id.json") or {} prefix = _ipcheck() -load_data_from_json("game_online") -cached_game_online = st.session_state.get("game_online") +load_data_from_json("game") +cached_game_online = st.session_state.get("game") load_data_from_json("team1") cached_team1 = st.session_state.get("team1")