Store replay files on local disc

This commit is contained in:
Maximilian Keßler 2023-11-20 13:05:20 +01:00
parent 06156d15e7
commit 9028c7401a
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 25 additions and 2 deletions

23
games.py Normal file
View file

@ -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

View file

@ -9,6 +9,7 @@ from hanabi.live.site_api import get
from bdr import describe_game from bdr import describe_game
from endgames import analyze_game_cached, full_analyze_game_cached from endgames import analyze_game_cached, full_analyze_game_cached
from games import get_game_json
# Init db connection # Init db connection
global_db_connection_manager.read_config() global_db_connection_manager.read_config()
@ -98,8 +99,7 @@ def collect_player_games():
def analyze_games(games): def analyze_games(games):
retval = {} retval = {}
for game_id in games.keys(): for game_id in games.keys():
game = get("export/" + str(game_id)) bdrs, termination = describe_game(get_game_json(game_id))
bdrs, termination = describe_game(game)
retval[game_id] = bdrs, termination retval[game_id] = bdrs, termination
return retval return retval