got actioncost working with yaml generation
parent
998f331bcc
commit
6ed2eea571
|
@ -1,37 +1,51 @@
|
||||||
import yaml
|
import yaml
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
|
import pprint
|
||||||
|
|
||||||
DBFILE = 'tmp.db'
|
DBFILE = 'tmp.db'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# delete DBfile and run fresh
|
# delete DBfile and run fresh
|
||||||
os.remove(DBFILE)
|
os.remove(DBFILE)
|
||||||
|
|
||||||
# Load in the yaml data
|
# Load in the yaml data
|
||||||
with open('basics.yaml') as yl:
|
with open('basics.yaml') as yl:
|
||||||
data = yaml.full_load(yl)
|
data = yaml.full_load(yl)
|
||||||
|
pprint.pprint(data)
|
||||||
## Get database connection
|
# Get a DB conn
|
||||||
conn = sqlite3.connect(DBFILE) # eventually hook this up to be the main db
|
conn = get_db_conn()
|
||||||
## Set pragmas
|
|
||||||
pragma1 = "PRAGMA synchronous=OFF;"
|
|
||||||
pragma2 = "PRAGMA count_changes=OFF;"
|
|
||||||
pragma3 = "PRAGMA journal_mode=MEMORY;"
|
|
||||||
pragma4 = "PRAGMA temp_store=MEMORY;"
|
|
||||||
pragma5 = "PRAGMA foreign_keys=ON;"
|
|
||||||
conn.execute(pragma1)
|
|
||||||
conn.execute(pragma2)
|
|
||||||
conn.execute(pragma3)
|
|
||||||
conn.execute(pragma4)
|
|
||||||
conn.execute(pragma5)
|
|
||||||
|
|
||||||
# call the functions to input to SQL
|
# call the functions to input to SQL
|
||||||
do_abilityscore(data['abilityscore'], conn)
|
do_abilityscore(data['abilityscore'], conn)
|
||||||
|
do_actioncost(data['actioncost'], conn)
|
||||||
|
|
||||||
|
def do_actioncost(data, conn):
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
table = """
|
||||||
|
CREATE TABLE actioncost (
|
||||||
|
actioncost_id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
abbr TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute(table)
|
||||||
|
|
||||||
|
inp_data = []
|
||||||
|
for i in data:
|
||||||
|
inp_data.append((i['name'], i['abbr']))
|
||||||
|
|
||||||
|
stmt = "INSERT INTO actioncost(name, abbr) VALUES (?,?)"
|
||||||
|
try:
|
||||||
|
conn.executemany(stmt,inp_data)
|
||||||
|
except:
|
||||||
|
print("Error creating actioncost")
|
||||||
|
else:
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
def do_abilityscore(data, conn):
|
def do_abilityscore(data, conn):
|
||||||
print(data)
|
print(data)
|
||||||
print(conn)
|
|
||||||
|
|
||||||
table = """
|
table = """
|
||||||
CREATE TABLE abilityscore (
|
CREATE TABLE abilityscore (
|
||||||
|
@ -57,6 +71,22 @@ CREATE TABLE abilityscore (
|
||||||
else:
|
else:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
def get_db_conn():
|
||||||
|
## Get database connection
|
||||||
|
conn = sqlite3.connect(DBFILE) # eventually hook this up to be the main db
|
||||||
|
## Set pragmas
|
||||||
|
pragma1 = "PRAGMA synchronous=OFF;"
|
||||||
|
pragma2 = "PRAGMA count_changes=OFF;"
|
||||||
|
pragma3 = "PRAGMA journal_mode=MEMORY;"
|
||||||
|
pragma4 = "PRAGMA temp_store=MEMORY;"
|
||||||
|
pragma5 = "PRAGMA foreign_keys=ON;"
|
||||||
|
conn.execute(pragma1)
|
||||||
|
conn.execute(pragma2)
|
||||||
|
conn.execute(pragma3)
|
||||||
|
conn.execute(pragma4)
|
||||||
|
conn.execute(pragma5)
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue