def update_database(new_date: datetime.datetime) -> None:
    db().begin('update_database')
    db().execute('DELETE FROM scryfall_version')
    db().execute(
        'SET FOREIGN_KEY_CHECKS=0'
    )  # Avoid needing to drop _cache_card (which has an FK relationship with card) so that the database continues to function while we perform the update.
    db().execute("""
        DELETE FROM card_color;
        DELETE FROM card_color_identity;
        DELETE FROM card_legality;
        DELETE FROM card_bug;
        DELETE FROM face;
        DELETE FROM printing;
        DELETE FROM card;
        DELETE FROM `set`;
    """)
    for s in fetcher.all_sets():
        insert_set(s)
    every_card_printing = fetcher.all_cards()
    insert_cards(every_card_printing)
    update_pd_legality()
    db().execute('INSERT INTO scryfall_version (last_updated) VALUES (%s)',
                 [dtutil.dt2ts(new_date)])
    db().execute(
        'SET FOREIGN_KEY_CHECKS=1'
    )  # OK we are done monkeying with the db put the FK checks back in place and recreate _cache_card.
    rebuild_cache()
    db().commit('update_database')
Ejemplo n.º 2
0
def update_database(new_version: str) -> None:
    db().begin()
    db().execute('DELETE FROM version')
    db().execute('DROP TABLE IF EXISTS _cache_card'
                 )  # We can't delete our data if we have FKs referencing it.
    db().execute("""
        DELETE FROM card_alias;
        DELETE FROM card_color;
        DELETE FROM card_color_identity;
        DELETE FROM card_legality;
        DELETE FROM card_subtype;
        DELETE FROM card_supertype;
        DELETE FROM card_bug;
        DELETE FROM face;
        DELETE FROM printing;
        DELETE FROM card;
        DELETE FROM `set`;
    """)
    cards = fetcher.all_cards()
    cards = fix_bad_mtgjson_data(cards)
    cards = add_hardcoded_cards(cards)
    melded_faces = []
    for _, c in cards.items():
        if c.get('layout') == 'meld' and c.get('name') == c['names'][2]:
            melded_faces.append(c)
        else:
            insert_card(c, update_index=False)
    for face in melded_faces:
        insert_card(face, update_index=False)
        first, second = face['names'][0:2]
        face['names'][0] = second
        face['names'][1] = first
        insert_card(face, update_index=False)
    sets = fetcher.all_sets()
    for _, s in sets.items():
        insert_set(s)
    check_layouts(
    )  # Check that the hardcoded list of layouts we're about to use is still valid.
    rs = db().select('SELECT id, name FROM rarity')
    for row in rs:
        db().execute('UPDATE printing SET rarity_id = %s WHERE rarity = %s',
                     [row['id'], row['name']])
    # Create the current Penny Dreadful format.
    get_format_id('Penny Dreadful', True)
    update_bugged_cards(False)
    update_pd_legality()
    db().execute('INSERT INTO version (version) VALUES (%s)', [new_version])
    db().commit()
def update_sets() -> dict:
    sets = load_sets()
    for s in fetcher.all_sets():
        if s['code'] not in sets.keys():
            insert_set(s)
    return load_sets()