From 6ffbcb9de1869a672620fe2b2024dfd692295a14 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: Fri, 31 Oct 2025 17:43:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B5=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_data.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/get_data.py b/get_data.py index ffecf94..8c061fa 100644 --- a/get_data.py +++ b/get_data.py @@ -133,6 +133,7 @@ def results_consumer(): and "teams" in payload["result"] ): # обновляем команды + game["data"]["result"]["game"]["fullScore"] = payload["result"]["fullScore"] for team in game["data"]["result"]["teams"]: if team["teamNumber"] != 0: box_team = [ @@ -561,12 +562,33 @@ async def game(): @app.get("/status.json") async def status(request: Request): + def color_for_status(status_value: str) -> str: + """Подбор цвета для статуса""" + status_value = str(status_value).lower() + if status_value in ["ok", "success", "live", "live_soon", "online"]: + return "🟢" + elif status_value in ["scheduled", "today_not_started", "upcoming"]: + return "🟡" + elif status_value in ["result", "resultconfirmed", "finished", "finished_today"]: + return "🔴" + elif status_value in ["no_game_today", "unknown", "none"]: + return "⚪" + else: + return "🔘" + data = { "league": LEAGUE, "team": TEAM, "game_id": GAME_ID, - "game_status": STATUS, # <= сюда приходит твой индикатор состояния + "game_status": STATUS, "statuses": [ + { + "name": TEAM, + "status": STATUS, + "ts": GAME_START_DT.strftime("%Y-%m-%d %H:%M") if GAME_START_DT else "N/A", + "link": LEAGUE + } + ] + [ { "name": item, "status": ( @@ -663,8 +685,16 @@ async def status(request: Request): """ for s in data["statuses"]: - status_text = str(s["status"]).strip() - color_class = "ok" if status_text.lower() == "ok" else "fail" + status_text = str(s["status"]).strip().lower() + + if any(x in status_text for x in ["ok", "success", "live", "live_soon", "online"]): + color_class = "ok" + elif any(x in status_text for x in ["scheduled", "today_not_started", "upcoming"]): + color_class = "warn" + elif any(x in status_text for x in ["result", "resultconfirmed", "finished", "finished_today"]): + color_class = "fail" + else: + color_class = "unknown" html += f""" {s["name"]} @@ -689,16 +719,42 @@ async def status(request: Request): @app.get("/scores.json") async def scores(): + game = get_latest_game_safe() + if not game: + # игры ещё нет или пришёл только частичный ответ + # отдаём пустую структуру, чтобы фронт не падал + return [ + {"Q": "Q1", "score1": "", "score2": ""}, + {"Q": "Q2", "score1": "", "score2": ""}, + {"Q": "Q3", "score1": "", "score2": ""}, + {"Q": "Q4", "score1": "", "score2": ""}, + ] + + game_data = game["data"] if "data" in game else game + result = game_data.get("result", {}) + game_info = result.get("game", {}) + + full_score = game_info.get("fullScore") + if not full_score: + # поле есть, но ещё пустое/None + return [ + {"Q": "Q1", "score1": "", "score2": ""}, + {"Q": "Q2", "score1": "", "score2": ""}, + {"Q": "Q3", "score1": "", "score2": ""}, + {"Q": "Q4", "score1": "", "score2": ""}, + ] + quarters = ["Q1", "Q2", "Q3", "Q4", "OT1", "OT2", "OT3", "OT4"] score_by_quarter = [{"Q": q, "score1": "", "score2": ""} for q in quarters] - full_score_list = latest_data["game"]["data"]["result"]["game"]["fullScore"].split( - "," - ) + + full_score_list = full_score.split(",") + for i, score_str in enumerate(full_score_list[: len(score_by_quarter)]): parts = score_str.split(":") if len(parts) == 2: score_by_quarter[i]["score1"] = parts[0] score_by_quarter[i]["score2"] = parts[1] + return score_by_quarter