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, cheat: bool = False) -> Dict: filename = GAMES_PATH / (str(game_id) + ('-cheat' if cheat else '')) if filename.exists(): with open(filename, 'r') as f: return json.load(f) if cheat: print('Failed to load replay of cheating game with id {}'.format(game_id)) return {} game = get("export/" + str(game_id)) with open(filename, 'w') as f: f.write(json.dumps(game, indent=2)) return game