pathfinder-2-sqlite-MIRROR/data/third_party_json/spells.py

42 lines
1.0 KiB
Python

import json
import sqlite3
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
## Get database connection
conn = sqlite3.connect('../../pf2.db')
for i in sorted_dicts:
do_sql(i)
# TODO write this function after sql schema drafted
def do_sql():
pass
if __name__ == "__main__":
main()