Store replay files on local disc
This commit is contained in:
parent
06156d15e7
commit
9028c7401a
2 changed files with 25 additions and 2 deletions
23
games.py
Normal file
23
games.py
Normal 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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue