27 lines
768 B
Python
27 lines
768 B
Python
import json
|
|
|
|
from typing import Dict, Optional
|
|
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, strategy: Optional[str] = None) -> Dict:
|
|
filename = GAMES_PATH / (str(game_id) + ('-{}'.format(strategy) if strategy is not None else ''))
|
|
if filename.exists():
|
|
with open(filename, 'r') as f:
|
|
return json.load(f)
|
|
|
|
if strategy is not None:
|
|
print('Failed to load replay of {} strategy version of game with id {}'.format(strategy, game_id))
|
|
return {}
|
|
|
|
game = get("export/" + str(game_id))
|
|
with open(filename, 'w') as f:
|
|
f.write(json.dumps(game, indent=2))
|
|
return game
|