def save_new_game(game, result): """Save new game results to database""" game.start_at = datetime.fromtimestamp(result["startOfGame"]) game.password = result["password"] game.scenario = result["scenarioID"] game.ranked = result["ranked"] game.gold_round = result["goldRound"] game.ai_level = result["aiLevel"] game.country_selection = result["countrySelection"] game.time_scale = result["timeScale"] game.team_setting = result["teamSettings"] game.victory_points = result["victoryPoints"] game.research_days_offset = result["researchDaysOffset"] game.research_time_scale = result["researchTimeScale"] game.team_victory_points = result["teamVictoryPoints"] game_map = Map.query.filter(Map.map_id == result["mapID"]).first() if game_map is None: game_map = Map() game_map.map_id = result["mapID"] game_map.slots = result["openSlots"] + result["numberOfPlayers"] db.session.add(game_map) db.session.commit() game.map_id = game_map.id get_players(game.game_id) db.session.commit()
def new_game(game_id): """Save new game results to database""" game = Game() game.game_id = game_id game.game_host = 'https://xgs8.c.bytro.com/' supremacy = Supremacy(game.game_id, game.game_host) while True: try: result = supremacy.game() except ServerChangeError as exception: new_server = str(exception) game.game_host = new_server supremacy.url = new_server continue break _update_game(game, result) game.start_at = datetime.fromtimestamp(result["startOfGame"]) game.password = result["password"] game.scenario = result["scenarioID"] game.ranked = result["ranked"] game.gold_round = result["goldRound"] game.ai_level = result["aiLevel"] game.country_selection = result["countrySelection"] game.time_scale = result["timeScale"] # game.team_setting = result["teamSettings"] game.victory_points = result["victoryPoints"] game.research_days_offset = result["researchDaysOffset"] if "researchTimeScale" in result: game.research_time_scale = result["researchTimeScale"] else: game.research_time_scale = 1.0 game.team_victory_points = result["teamVictoryPoints"] game_map = Map.query.filter(Map.map_id == result["mapID"]).first() if game_map is None: game_map = Map() game_map.map_id = result["mapID"] game_map.name = result["mapID"] game_map.slots = result["openSlots"] + result["numberOfPlayers"] db.session.add(game_map) db.session.commit() game.map_id = game_map.id db.session.add(game) db.session.commit() return game