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