update export method: parses extra parameters and returns if game was cheaty

This commit is contained in:
Maximilian Keßler 2023-03-11 20:10:40 +01:00
parent 46cc2c50ee
commit 777d374ba4
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -28,11 +28,13 @@ def download_games(variant_id, name=None):
print('Downloaded and stored {} entries for variant {} ({})'.format(num_entries, variant_id, name))
commit()
def export_game(game_id) -> bool:
# requires seed AND game to already have an entry in database
# return: (successfully exported game, game without cheat options, null if not exported)
def export_game(game_id) -> [bool, bool]:
r = get("export/{}".format(game_id))
if r is None:
print("Failed to export game id {}".format(game_id))
return False
return False, None
assert(r['id'] == game_id)
deck = compress_deck([DeckCard.from_json(card) for card in r['deck']])
with conn.cursor() as cur:
@ -41,11 +43,25 @@ def export_game(game_id) -> bool:
actions = compress_actions([Action.from_json(a) for a in r['actions']])
except:
print("Unknown action while exporting game id {}".format(game_id))
return False
raise
return False, None
options = r.get('options', {})
deck_plays = options.get('deckPlays', False)
one_extra_card = options.get('oneExtraCard', False)
one_less_card = options.get('oneLessCard', False)
all_or_nothing = options.get('allOrNothing', False)
with conn.cursor() as cur:
cur.execute("UPDATE games SET actions=(%s) WHERE id=(%s);", (actions, game_id))
cur.execute(
"UPDATE games SET"
"deck_plays=(%s)"
"one_extra_card=(%s)"
"one_less_card=(%s)"
"all_or_nothing=(%s)"
"actions=(%s)"
"WHERE id=(%s);",
(deck_plays, one_extra_card, one_less_card, all_or_nothing, actions, game_id))
conn.commit()
return True
return True, not any(deck_plays, one_extra_card, one_less_card, all_or_nothing)
if __name__ == "__main__":
export_game(913436)