diff --git a/data/third_party_json/spells.py b/data/third_party_json/spells.py index a88fd09..f17c08b 100644 --- a/data/third_party_json/spells.py +++ b/data/third_party_json/spells.py @@ -38,6 +38,14 @@ def main(): traits = c.fetchall() # print(traits) + # load in ids for spelltypes from spelltypes table so we only call this once + # instead of every spell + stmt = "SELECT spelltypes_id, name FROM spelltypes" + c = conn.cursor() + c.execute(stmt) + stypes = c.fetchall() + # print(traits) + id = 0 for i in sorted_dicts: @@ -47,8 +55,27 @@ def main(): do_range_numbers(i,id,conn) do_sources_pages(i,id,conn) do_spell_traits(i,id,conn,traits) + do_spell_types(i,id,conn,stypes) # TODO do all the traits, FK stuff etc... +def do_spell_types(i,id,conn,stypes): + res = 0 + for j in stypes: + if i['type'] == j[1]: + res = j[0] + print(id , res) + + inp = (res, id) + + stmt = "UPDATE spells SET spelltypes_id=? WHERE spells_id=?" + + try: + conn.execute(stmt, inp) + except: + print("Error updating spell types") + else: + conn.commit() + def do_spell_traits(i, id, conn, traits): # get list of traits from the json and capitalize first letter diff --git a/schema/spells.sql b/schema/spells.sql index da18251..d2efcda 100644 --- a/schema/spells.sql +++ b/schema/spells.sql @@ -34,7 +34,7 @@ CREATE TABLE spells ( level INTEGER, -- scraped from github repo trigger TEXT, -- TODO in spells.py descr TEXT, -- scraped from github repo - spelltypes_id INTEGER, -- TODO in spells.py + spelltypes_id INTEGER, -- generated from spells.py range_text TEXT, -- scraped from github repo range_ft INTEGER, -- generated from text in spells.py targets TEXT, -- TODO in spells.py