From dd63bc170ec2a9c49edac7d0feb06c0b0f35479e 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 18:16:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20live-status=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5.=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE,=20=D0=BA=D0=B0=D0=BA=20=D0=BC=D0=B0=D1=82=D1=87=20?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=BD=D1=87=D0=B5=D0=BD,=20=D0=B2=D1=8B?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=D1=81=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=20=D0=B8=D0=B3=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_data.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/get_data.py b/get_data.py index 3cb9b4b..5668bf0 100644 --- a/get_data.py +++ b/get_data.py @@ -168,6 +168,49 @@ def results_consumer(): "data": incoming_status if incoming_status is not None else payload, } + elif "live-status" in source: + # просто сохраним, как и остальные + latest_data[source] = { + "ts": msg["ts"], + "data": incoming_status if incoming_status is not None else payload, + } + + # попытка ДОПОЛНИТЕЛЬНО обновить глобальный STATUS по live-status + try: + ls_data = payload.get("result") or payload # иногда сразу result + # тут нужно посмотреть, какое именно поле у тебя в live-status + # допустим, там есть что-то вроде "status" или "gameStatus" + raw_ls_status = ( + ls_data.get("status") + or ls_data.get("gameStatus") + or ls_data.get("state") + ) + + if raw_ls_status: + raw_ls_status = str(raw_ls_status).lower() + + # варианты, которые считаем "матч окончен" + finished_markers = [ + "finished", + "result", + "resultconfirmed", + "ended", + "game over", + "final", + ] + + if any(m in raw_ls_status for m in finished_markers): + # перезатираем глобальный статус — он более актуальный + # если матч сегодня — делаем finished_today, иначе просто finished + from datetime import datetime + + if GAME_START_DT and GAME_START_DT.date() == datetime.now().date(): + globals()["STATUS"] = "finished_today" + else: + globals()["STATUS"] = "finished" + except Exception as e: + print("results_consumer: live-status postprocess error:", e) + else: if source == "game": has_game_already = "game" in latest_data @@ -1500,9 +1543,35 @@ async def regular_standings(): @app.get("/live_status.json") async def live_status(): + # если матч реально идёт/вот-вот — пытаемся отдать то, что есть if STATUS in ["live", "live_soon"]: - return [latest_data["live-status"]["data"]["result"]] + ls = latest_data.get("live-status") + + if not ls: + # live-status ещё не прилетел + return [{"foulsA": 0, "foulsB": 0}] + + raw = ls.get("data") + + # 1) если это уже готовый dict и в нём есть result → как было раньше + if isinstance(raw, dict): + # иногда API кладёт всё прямо в root, иногда внутрь result + if "result" in raw and isinstance(raw["result"], dict): + return [raw["result"]] + else: + # отдадим как есть, но в списке, чтобы фронт не сломать + return [raw] + + # 2) если это просто строка статуса ("ok" / "no-status" / "error") + if isinstance(raw, str): + return [{ + "status": raw + }] + + # fallback + return [{"foulsA": 0, "foulsB": 0}] else: + # матч не идёт — как у тебя было return [{"foulsA": 0, "foulsB": 0}]