From 5f50cd22315706a4d8e13efd990a262571044c9b Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 8 Aug 2019 21:01:12 -0500 Subject: [PATCH] got spells.py fixing the nethys sources_pages field --- data/third_party_json/spells.py | 26 ++++++++++++++++++++++++++ schema/spells.sql | 22 +++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/data/third_party_json/spells.py b/data/third_party_json/spells.py index 8244200..b8bb021 100644 --- a/data/third_party_json/spells.py +++ b/data/third_party_json/spells.py @@ -36,8 +36,34 @@ def main(): # insert basics of a spell do_basic_sql(i, id, conn) do_range_numbers(i,id,conn) + do_sources_pages(i,id,conn) # TODO do all the traits, FK stuff etc... +def do_sources_pages(i, id, conn): + if 'source' not in i: + return + print(i) + + res = '' + source_id = 0 + # Do Core Rulebook branch + if "Core Rulebook" in i['source']: + res = i['source'].replace('Core Rulebook pg.','').strip() + source_id = 1 + + stmt = "UPDATE spells SET sources_id=?, sources_pages=? WHERE spells_id=?" + inp = (source_id, res, id) + + try: + conn.execute(stmt, inp) + except: + print("Error updating sources") + else: + conn.commit() + + + + def do_range_numbers(i, id, conn): # no need to do range if 'range' not in i: diff --git a/schema/spells.sql b/schema/spells.sql index f89d039..049ab51 100644 --- a/schema/spells.sql +++ b/schema/spells.sql @@ -28,17 +28,17 @@ CREATE TABLE spellschools ( -- UNIQUE as sanity requires :) CREATE TABLE spells ( spells_id INTEGER PRIMARY KEY, - sources_id INTEGER NOT NULL, - sources_pages TEXT, - name TEXT NOT NULL UNIQUE, - level INTEGER, - trigger TEXT, - descr TEXT, - spelltypes_id INTEGER, - range_text TEXT, - range_ft INTEGER, - targets TEXT, - nethysurl TEXT, + sources_id INTEGER NOT NULL, -- manually entered right now + sources_pages TEXT, -- TODO convert to our format in spells.py + name TEXT NOT NULL UNIQUE, -- scraped from github repo + 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 + range_text TEXT, -- scraped from github repo + range_ft INTEGER, -- generated from text in spells.py + targets TEXT, -- TODO in spells.py + nethysurl TEXT, -- scraped from github repo FOREIGN KEY (sources_id) REFERENCES sources(sources_id), FOREIGN KEY (spelltypes_id) REFERENCES spelltypes(spelltypes_id) );