2019-08-08 16:37:08 -04:00
|
|
|
import json
|
2019-08-08 18:28:33 -04:00
|
|
|
import sqlite3
|
2019-08-08 16:37:08 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
# load json into python
|
|
|
|
print("loading json")
|
|
|
|
## read file into memory
|
|
|
|
with open('spells.json') as f:
|
|
|
|
# raw_data = f.read()
|
|
|
|
data = json.load(f)
|
|
|
|
print("Imported {} spells.".format(len(data)))
|
|
|
|
# alphabetize spells into a list
|
|
|
|
sorted_names = []
|
|
|
|
for i in data:
|
|
|
|
sorted_names.append(i['name'])
|
|
|
|
sorted_names.sort()
|
|
|
|
# print(sorted_names)
|
|
|
|
|
|
|
|
# get list of dicts in order
|
|
|
|
sorted_dicts = [] # sorted by ['name'] alphabetically
|
|
|
|
for i in sorted_names:
|
|
|
|
for x in data:
|
|
|
|
# yes, I know this is double nested and not that efficient; don't
|
|
|
|
# care yet, it's not that many items
|
|
|
|
if x['name'] == i:
|
|
|
|
sorted_dicts.append(x)
|
|
|
|
|
|
|
|
# NOW we can go alphabetically spell by spell
|
2019-08-08 18:28:33 -04:00
|
|
|
|
|
|
|
## Get database connection
|
|
|
|
conn = sqlite3.connect('../../pf2.db')
|
2019-08-08 16:37:08 -04:00
|
|
|
for i in sorted_dicts:
|
|
|
|
do_sql(i)
|
|
|
|
|
|
|
|
# TODO write this function after sql schema drafted
|
|
|
|
def do_sql():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|