示例#1
0
def update_game(s):
    g_id = s['id']
    opt = s['options']
    game = session.query(Game).filter(Game.game_id == g_id).first()
    if game is None:
        logger.info(f"{g_id} doesn't exist in db.")
        return -1
    num_players = session.query(
        Game.num_players).filter(Game.game_id == g_id).scalar()
    if num_players is not None:
        return 0
    game.num_players = opt['numPlayers']
    if game.starting_player is None:
        game.starting_player = opt['startingPlayer']
    game.variant_id = opt['variantID']
    game.variant = opt['variantName']
    game.timed = opt['timed']
    game.time_base = opt['timeBase']
    game.time_per_turn = opt['timePerTurn']
    game.speedrun = opt['speedrun']
    game.card_cycle = opt['cardCycle']
    game.deck_plays = opt['deckPlays']
    game.empty_clues = opt['emptyClues']
    game.one_extra_card = opt['oneExtraCard']
    game.one_less_card = opt['oneLessCard']
    game.all_or_nothing = opt['allOrNothing']
    game.detrimental_characters = opt['detrimentalCharacters']
    game.score = s['score']
    game.num_turns = s['numTurns']
    game.end_condition = s['endCondition']
    game.date_time_started = s['datetimeStarted']
    game.date_time_finished = s['datetimeFinished']
    game.num_games_on_this_seed = s['numGamesOnThisSeed']
    game.tags = s['tags']
    return 1
示例#2
0
def load_from_files(all_games):
    for g in all_games.values():
        s = u.open_stats_by_game_id(g['players'][0], g['id'])
        d.load_deck(g)
        d.load_game(g, s)
        # d.load_game_empty(g)
        d.load_actions(g)
        d.load_notes(g)
        d.session.commit()
        logger.info(g['id'])
示例#3
0
def load_slots(all_games):
    for g in all_games:
        d.load_slots(g)
        d.session.commit()
        logger.info(g.game_id)
示例#4
0
def load_cards(all_games):
    for g in all_games:
        d.update_action_types(g)
        # d.load_card_actions_and_clues(g)
        d.session.commit()
        logger.info(g.game_id)
示例#5
0
from datetime import datetime
from json.decoder import JSONDecodeError

import requests
from sqlalchemy import func

from database.db_connect import Game, session
from py.utils import logger
import py.utils as u
import database.db_load as d

last_id = session.query(func.max(Game.game_id)).scalar()
# last_id = 443662
logger.info(
    f'{datetime.now().strftime("%d.%m.%Y %H:%M:%S")}\tstart:\t{last_id}')
req_session = requests.Session()
histories = {}
while True:
    g_id = last_id + 1
    g = u.export_game(g_id, req_session)
    if g != {}:
        if len(g['players']) == 0:
            logger.error(g_id)
            last_id += 1
            continue
        player = g['players'][0]
        if player in histories.keys():
            s = u.open_stats_by_game_id(histories[player], g_id)
        else:
            try:
                response = u.open_stats_from_id_start(player, last_id,