download: fix parsing of var id, better error handling

This commit is contained in:
Maximilian Keßler 2023-05-08 23:27:47 +02:00
parent c47ca7ccc5
commit edcdaa8fd2
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -38,6 +38,7 @@ def export_game(game_id) -> [bool, bool]:
res = cur.fetchall()
if len(res) == 1:
print(res)
return
else:
print('game is completely new')
# return
@ -53,7 +54,7 @@ def export_game(game_id) -> [bool, bool]:
num_players = len(r['players'])
seed = r['seed']
options = r.get('options', {})
var_id = variant_id(options['variant'])
var_id = variant_id(options.get('variant', 'No Variant'))
deck_plays = options.get('deckPlays', False)
one_extra_card = options.get('oneExtraCard', False)
one_less_card = options.get('oneLessCard', False)
@ -62,6 +63,7 @@ def export_game(game_id) -> [bool, bool]:
deck = [DeckCard.from_json(card) for card in r['deck']]
except KeyError:
print('Error parsing JSON when exporting game {}'.format(game_id))
raise
# need to play through the game once to find out its score
game = GameState(HanabiInstance(deck, num_players))