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