spells.py now converts text range data to integer
parent
85f251adc3
commit
d9ffb127e4
|
@ -33,10 +33,41 @@ def main():
|
||||||
id = 0
|
id = 0
|
||||||
for i in sorted_dicts:
|
for i in sorted_dicts:
|
||||||
id += 1
|
id += 1
|
||||||
do_sql(i, id, conn)
|
# insert basics of a spell
|
||||||
|
do_basic_sql(i, id, conn)
|
||||||
|
do_range_numbers(i,id,conn)
|
||||||
|
# TODO do all the traits, FK stuff etc...
|
||||||
|
|
||||||
# TODO write this function after sql schema drafted
|
def do_range_numbers(i, id, conn):
|
||||||
def do_sql(i, id, conn):
|
# no need to do range
|
||||||
|
if 'range' not in i:
|
||||||
|
return
|
||||||
|
rg = -1
|
||||||
|
# convert range_text to an integer representation
|
||||||
|
if i['range'] == 'touch':
|
||||||
|
rg = 0
|
||||||
|
elif i['range'] == 'planetary':
|
||||||
|
rg = 999999999
|
||||||
|
# is the only one in CRB with emanation 40' from current scraping
|
||||||
|
elif i['name'] == 'Repulsion':
|
||||||
|
rg = 40
|
||||||
|
else:
|
||||||
|
# DO SPLITS
|
||||||
|
splits = i['range'].split(' ')
|
||||||
|
# print(splits)
|
||||||
|
rg = splits[0]
|
||||||
|
inp = (rg, id)
|
||||||
|
stmt = "UPDATE spells SET range_ft=? WHERE spells_id=?"
|
||||||
|
try:
|
||||||
|
conn.execute(stmt, inp)
|
||||||
|
except:
|
||||||
|
print("Error updating range_ft")
|
||||||
|
else:
|
||||||
|
conn.commit()
|
||||||
|
# print("Successfully updated range_ft")
|
||||||
|
|
||||||
|
|
||||||
|
def do_basic_sql(i, id, conn):
|
||||||
print("Doing spell id #{}: {}".format(id, i['name']))
|
print("Doing spell id #{}: {}".format(id, i['name']))
|
||||||
stmt = """INSERT INTO spells (
|
stmt = """INSERT INTO spells (
|
||||||
spells_id,
|
spells_id,
|
||||||
|
@ -44,11 +75,10 @@ def do_sql(i, id, conn):
|
||||||
sources_pages,
|
sources_pages,
|
||||||
nethysurl,
|
nethysurl,
|
||||||
name,
|
name,
|
||||||
source,
|
|
||||||
level,
|
level,
|
||||||
descr,
|
descr,
|
||||||
range_text)
|
range_text)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?)"""
|
VALUES (?,?,?,?,?,?,?,?)"""
|
||||||
|
|
||||||
rge = None
|
rge = None
|
||||||
if 'range' in i:
|
if 'range' in i:
|
||||||
|
@ -58,12 +88,14 @@ def do_sql(i, id, conn):
|
||||||
if 'description' in i:
|
if 'description' in i:
|
||||||
dscr = i['description']
|
dscr = i['description']
|
||||||
|
|
||||||
inp = (id, 1, None, i['nethysUrl'], i['name'], i['source'], i['level'], dscr, rge)
|
inp = (id, 1, i['source'], i['nethysUrl'], i['name'], i['level'], dscr, rge)
|
||||||
try:
|
try:
|
||||||
conn.execute(stmt, inp)
|
conn.execute(stmt, inp)
|
||||||
except:
|
except:
|
||||||
print("Error")
|
print("Error inserting row")
|
||||||
conn.commit()
|
else:
|
||||||
|
conn.commit()
|
||||||
|
# print("Successfully inserted row")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -24,21 +24,21 @@ CREATE TABLE spellschools (
|
||||||
FOREIGN KEY (sources_id) REFERENCES sources(sources_id)
|
FOREIGN KEY (sources_id) REFERENCES sources(sources_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- TODO eventually once data is finalized, lock down variables as NOT NULL /
|
||||||
|
-- UNIQUE as sanity requires :)
|
||||||
CREATE TABLE spells (
|
CREATE TABLE spells (
|
||||||
spells_id INTEGER PRIMARY KEY,
|
spells_id INTEGER PRIMARY KEY,
|
||||||
sources_id INTEGER NOT NULL,
|
sources_id INTEGER NOT NULL,
|
||||||
sources_pages TEXT,
|
sources_pages TEXT,
|
||||||
nethysurl TEXT,
|
|
||||||
name TEXT NOT NULL UNIQUE,
|
name TEXT NOT NULL UNIQUE,
|
||||||
source TEXT,
|
level INTEGER,
|
||||||
level INTEGER NOT NULL,
|
|
||||||
trigger TEXT,
|
trigger TEXT,
|
||||||
descr TEXT NOT NULL,
|
descr TEXT,
|
||||||
spelltypes_id INTEGER,
|
spelltypes_id INTEGER,
|
||||||
range_text TEXT,
|
range_text TEXT,
|
||||||
range_ft INTEGER,
|
range_ft INTEGER,
|
||||||
targets TEXT,
|
targets TEXT,
|
||||||
|
nethysurl TEXT,
|
||||||
FOREIGN KEY (sources_id) REFERENCES sources(sources_id),
|
FOREIGN KEY (sources_id) REFERENCES sources(sources_id),
|
||||||
FOREIGN KEY (spelltypes_id) REFERENCES spelltypes(spelltypes_id)
|
FOREIGN KEY (spelltypes_id) REFERENCES spelltypes(spelltypes_id)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue