From 85f251adc3f6867f60375b7d766a0d5473d7c719 Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 8 Aug 2019 18:05:21 -0500 Subject: [PATCH] still working on spell import --- data/third_party_json/spells.py | 35 ++++++++++++++++++++++++++++++--- schema/spells.sql | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/data/third_party_json/spells.py b/data/third_party_json/spells.py index 169e370..3863707 100644 --- a/data/third_party_json/spells.py +++ b/data/third_party_json/spells.py @@ -29,12 +29,41 @@ def main(): ## Get database connection conn = sqlite3.connect('../../pf2.db') + + id = 0 for i in sorted_dicts: - do_sql(i) + id += 1 + do_sql(i, id, conn) # TODO write this function after sql schema drafted -def do_sql(): - pass +def do_sql(i, id, conn): + print("Doing spell id #{}: {}".format(id, i['name'])) + stmt = """INSERT INTO spells ( + spells_id, + sources_id, + sources_pages, + nethysurl, + name, + source, + level, + descr, + range_text) + VALUES (?,?,?,?,?,?,?,?,?)""" + + rge = None + if 'range' in i: + rge = i['range'] + + dscr = None + if 'description' in i: + dscr = i['description'] + + inp = (id, 1, None, i['nethysUrl'], i['name'], i['source'], i['level'], dscr, rge) + try: + conn.execute(stmt, inp) + except: + print("Error") + conn.commit() if __name__ == "__main__": diff --git a/schema/spells.sql b/schema/spells.sql index 749498c..22bcbb5 100644 --- a/schema/spells.sql +++ b/schema/spells.sql @@ -35,7 +35,7 @@ CREATE TABLE spells ( level INTEGER NOT NULL, trigger TEXT, descr TEXT NOT NULL, - spelltypes_id INTEGER NOT NULL, + spelltypes_id INTEGER, range_text TEXT, range_ft INTEGER, targets TEXT,