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