24 lines
510 B
Python
24 lines
510 B
Python
|
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
|