diff --git a/get_data_new.py b/get_data_new.py index 36496b6..56bc0b0 100644 --- a/get_data_new.py +++ b/get_data_new.py @@ -164,7 +164,7 @@ def atomic_write_json(path: str, data: Any) -> None: # 1. Готовим данные заранее # ensure_ascii=False чтобы не терять юникод, indent=None чтобы не раздувать файл payload = json.dumps(data, ensure_ascii=False, separators=(",", ":")) - + path = "static/" + path + ".json" target = Path(path) tmp_fd, tmp_path = tempfile.mkstemp( dir=target.parent, @@ -724,12 +724,12 @@ def render_loop(stop_event: threading.Event, out_name: str = "game") -> None: rs = state.get("result", {}) if isinstance(rs, dict) and "live_status" in rs: live_status_to_write = [rs["live_status"]] - atomic_write_json(live_status_to_write, "live_status") + atomic_write_json("live_status", live_status_to_write) except Exception as e: logger.debug(f"[RENDER_THREAD] skip live_status write: {e}") try: - atomic_write_json(state.get("result", {}), out_name) + atomic_write_json(out_name, state.get("result", {})) except Exception as e: logger.debug(f"[RENDER_THREAD] skip {out_name}.json write: {e}") @@ -837,7 +837,7 @@ def Referee(merged: dict, *, out_dir: str = "static") -> None: ), ) out_path = "referee" - atomic_write_json(referees, out_path) + atomic_write_json(out_path, referees) logging.info("Сохранил payload: {out_path}") except Exception as e: @@ -1043,7 +1043,7 @@ def render_once_after_game( Referee(state) Play_By_Play(state) - atomic_write_json(state["result"], out_name) + atomic_write_json(out_name, state["result"]) logger.info("[RENDER_ONCE] финальные json сохранены успешно") @@ -1282,7 +1282,7 @@ def Json_Team_Generation( ) # пишем полный ростер команды - atomic_write_json(sorted_team, who) + atomic_write_json(who, sorted_team) logger.info(f"Сохранил payload: {who}.json") # топ-игроки по очкам/подборам/ассистам и т.д. @@ -1306,7 +1306,7 @@ def Json_Team_Generation( player["foul"] = "" top_name = f"top{who.replace('t', 'T')}" - atomic_write_json(top_sorted_team, top_name) + atomic_write_json(top_name, top_sorted_team) logger.info(f"Сохранил payload: {top_name}.json") # кто прямо сейчас на площадке @@ -1319,7 +1319,7 @@ def Json_Team_Generation( key=lambda x: int(x.get("num") or 0), ) started_name = f"started_{who}" - atomic_write_json(started_team, started_name) + atomic_write_json(started_name, started_team) logger.info(f"Сохранил payload: {started_name}.json") @@ -1589,7 +1589,7 @@ def Team_Both_Stat(merged: dict) -> None: } ) - atomic_write_json(result_json, "team_stats") + atomic_write_json("team_stats", result_json) logger.info("Сохранил payload: team_stats.json") except Exception as e: @@ -1660,7 +1660,7 @@ def Pregame_data_json(data: dict) -> None: "fouls": round((data_team["totalStats"]["foul"] / data_team["games"]), 1), } teams.append(temp_team) - atomic_write_json(teams, "team_comparison") + atomic_write_json("team_comparison", teams) logger.info("Сохранил payload: team_comparison.json") @@ -1720,7 +1720,7 @@ def Scores_Quarter(merged: dict) -> None: else: logger.debug("Нет данных по счёту, сохраняем пустые значения.") - atomic_write_json(score_by_quarter, "scores") + atomic_write_json("scores", score_by_quarter) logger.info("Сохранил payload: scores.json") except Exception as e: @@ -1853,7 +1853,7 @@ def Standing_func( standings_payload = df.to_dict(orient="records") filename = f"standings_{league}_{comp_name}" - atomic_write_json(standings_payload, filename, out_dir) + atomic_write_json(filename, standings_payload) logger.info(f"[STANDINGS_THREAD] сохранил {filename}.json") elif item.get("playoffPairs"): @@ -1863,7 +1863,7 @@ def Standing_func( standings_payload = df.to_dict(orient="records") filename = f"standings_{league}_{comp_name}" - atomic_write_json(standings_payload, filename, out_dir) + atomic_write_json(filename, standings_payload) logger.info( f"[STANDINGS_THREAD] saved {filename}.json (playoffPairs, {len(standings_payload)} rows)" )