Пример #1
0
def process_logs() -> None:
    init()
    ids_to_process = next_ids()
    if not ids_to_process:
        return
    placeholders = ', '.join('%s' for v in ids_to_process)
    sql = f"""
        SELECT
            id AS game_id,
            log
        FROM
            game
        WHERE
            id IN ({placeholders})
    """
    rs = logsite_db().select(sql, ids_to_process)
    values = []
    for r in rs:
        entries = process_log(r['log'])
        for entry in entries:
            values.append([r['game_id']] + list(entry))
    sql = 'INSERT INTO _game_card_person (game_id, mtgo_username, name) VALUES '
    sql += ', '.join('(' + ', '.join(str(sqlescape(v)) for v in vs) + ')'
                     for vs in values)
    logsite_db().execute(sql)
Пример #2
0
def init() -> None:
    sql = """
        CREATE TABLE IF NOT EXISTS _game_card_person (
            game_id INT NOT NULL,
            name NVARCHAR(100) NOT NULL,
            mtgo_username VARCHAR(50) NOT NULL
        ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
    """
    logsite_db().execute(sql)
Пример #3
0
def next_ids() -> List[int]:
    sql = """
        SELECT
            id AS game_id
        FROM
            game
        WHERE
            id NOT IN (
                SELECT
                    game_id
                FROM
                    _game_card_person
            )
        ORDER BY
            id
        LIMIT
            10000
    """
    return logsite_db().values(sql)