поправил чтение json файлов

This commit is contained in:
2025-10-24 14:15:37 +03:00
parent efa4812b09
commit d7c819357d

View File

@@ -285,11 +285,7 @@ if "player2" not in st.session_state:
st.session_state.player2 = None st.session_state.player2 = None
myhost = platform.node() FOLDER_JSON = "static"
if sys.platform.startswith("win"): # было: if platform == "win32":
FOLDER_JSON = "JSON"
else:
FOLDER_JSON = "static"
def get_ip_address(): def get_ip_address():
@@ -414,9 +410,7 @@ def rewrite_file(filename: str, data: dict, directory: str = "JSON") -> None:
os.makedirs(directory, exist_ok=True) os.makedirs(directory, exist_ok=True)
host_prefix = _ipcheck() filepath = os.path.join(directory, f"{filename}.json")
filepath = os.path.join(directory, f"{host_prefix}{filename}.json")
# print(filepath) # оставил как у тебя; можно заменить на logger.debug при желании # print(filepath) # оставил как у тебя; можно заменить на logger.debug при желании
try: try:
@@ -431,16 +425,16 @@ ip_check = read_match_id_json("match_id.json") or {}
prefix = _ipcheck() prefix = _ipcheck()
load_data_from_json(f"{prefix}game_online") load_data_from_json("game_online")
cached_game_online = st.session_state.get("game_online") cached_game_online = st.session_state.get("game_online")
load_data_from_json(f"{prefix}team1") load_data_from_json("team1")
cached_team1 = st.session_state.get("team1") cached_team1 = st.session_state.get("team1")
load_data_from_json(f"{prefix}team2") load_data_from_json("team2")
cached_team2 = st.session_state.get("team2") cached_team2 = st.session_state.get("team2")
load_data_from_json(f"{prefix}referee") load_data_from_json("referee")
cached_referee = st.session_state.get("referee") cached_referee = st.session_state.get("referee")
# standings — может не быть тега/файла # standings — может не быть тега/файла
@@ -455,29 +449,29 @@ if isinstance(cached_game_online, dict):
.replace(" ", "_") .replace(" ", "_")
) )
if league_tag: if league_tag:
load_data_from_json(f"{prefix}standings_{league_tag}_{comp_name}") load_data_from_json(f"standings_{league_tag}_{comp_name}")
cached_standings = ( cached_standings = (
st.session_state.get(f"standings_{league_tag}_{comp_name}") if league_tag else None st.session_state.get(f"standings_{league_tag}_{comp_name}") if league_tag else None
) )
load_data_from_json(f"{prefix}scores_quarter") load_data_from_json("scores_quarter")
cached_scores_quarter = st.session_state.get("scores_quarter") cached_scores_quarter = st.session_state.get("scores_quarter")
load_data_from_json(f"{prefix}play_by_play") load_data_from_json("play_by_play")
cached_play_by_play = st.session_state.get("play_by_play") cached_play_by_play = st.session_state.get("play_by_play")
load_data_from_json(f"{prefix}team_stats") load_data_from_json("team_stats")
cached_team_stats = st.session_state.get("team_stats") cached_team_stats = st.session_state.get("team_stats")
load_data_from_json(f"{prefix}scores") load_data_from_json("scores")
cached_scores = st.session_state.get("scores") or [] # важно! cached_scores = st.session_state.get("scores") or [] # важно!
load_data_from_json(f"{prefix}live_status") load_data_from_json("live_status")
cached_live_status = st.session_state.get("live_status") cached_live_status = st.session_state.get("live_status")
load_data_from_json(f"{prefix}schedule") load_data_from_json("schedule")
cached_schedule = st.session_state.get("schedule") cached_schedule = st.session_state.get("schedule")
load_data_from_json(f"{prefix}team_comparison") load_data_from_json("team_comparison")
cached_team_comparison = st.session_state.get("team_comparison") cached_team_comparison = st.session_state.get("team_comparison")