From 9028c7401a1e64e5be34829bdee4c97782841103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 20 Nov 2023 13:05:20 +0100 Subject: [PATCH] Store replay files on local disc --- games.py | 23 +++++++++++++++++++++++ get_sheet.py | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 games.py diff --git a/games.py b/games.py new file mode 100644 index 0000000..1411d6a --- /dev/null +++ b/games.py @@ -0,0 +1,23 @@ +import json + +from typing import Dict +from pathlib import Path + +from hanabi.live.site_api import get + +GAMES_PATH = Path('games') + +if not GAMES_PATH.exists(): + GAMES_PATH.mkdir(parents=True) + + +def get_game_json(game_id: int) -> Dict: + filename = GAMES_PATH / str(game_id) + if filename.exists(): + with open(filename, 'r') as f: + return json.load(f) + + game = get("export/" + str(game_id)) + with open(filename, 'w') as f: + f.write(json.dumps(game, indent=2)) + return game diff --git a/get_sheet.py b/get_sheet.py index 013fd22..493b396 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -9,6 +9,7 @@ from hanabi.live.site_api import get from bdr import describe_game from endgames import analyze_game_cached, full_analyze_game_cached +from games import get_game_json # Init db connection global_db_connection_manager.read_config() @@ -98,8 +99,7 @@ def collect_player_games(): def analyze_games(games): retval = {} for game_id in games.keys(): - game = get("export/" + str(game_id)) - bdrs, termination = describe_game(game) + bdrs, termination = describe_game(get_game_json(game_id)) retval[game_id] = bdrs, termination return retval