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