Merge branch 'begin-yaml-transition'
commit
0bcfd98e46
|
@ -1,5 +1,6 @@
|
|||
# Custom files
|
||||
pf2.db
|
||||
tmp.db
|
||||
spells_temp.txt
|
||||
|
||||
##############################
|
||||
|
|
|
@ -0,0 +1,246 @@
|
|||
import yaml
|
||||
import sqlite3
|
||||
import os
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
DBFILE = 'tmp.db'
|
||||
|
||||
def main():
|
||||
# delete DBfile and run fresh
|
||||
os.remove(DBFILE)
|
||||
# Load in the yaml data
|
||||
with open('basics.yaml') as yl:
|
||||
data = yaml.full_load(yl)
|
||||
pprint.pprint(data)
|
||||
# Get a DB conn
|
||||
conn = get_db_conn()
|
||||
# call the functions to input to SQL
|
||||
do_abilityscore(data['abilityscore'], conn)
|
||||
do_actioncost(data['actioncost'], conn)
|
||||
do_alignment(data['alignment'], conn)
|
||||
do_frequency(data['frequency'], conn)
|
||||
do_langrarity(data['lang_rarity'], conn)
|
||||
do_movement(data['movement'], conn)
|
||||
do_size(data['size'], conn)
|
||||
do_weaponcategory(data['weaponcategory'], conn)
|
||||
|
||||
def do_size(data, conn):
|
||||
table = """
|
||||
CREATE TABLE size (
|
||||
size_id INTEGER PRIMARY KEY,
|
||||
short_name TEXT NOT NULL UNIQUE,
|
||||
space_in_ft INTEGER NOT NULL,
|
||||
reach_tall_ft INTEGER NOT NULL,
|
||||
reach_long_ft INTEGER NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i['name'], i['space_in_ft'], i['reach_tall_ft'], i['reach_long_ft']))
|
||||
|
||||
stmt = "INSERT INTO size (short_name, space_in_ft, reach_tall_ft, reach_long_ft) VALUES (?,?,?,?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
print("Error creating size")
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_weaponcategory(data, conn):
|
||||
table = """
|
||||
CREATE TABLE weaponcategory (
|
||||
weaponcategory_id INTEGER PRIMARY KEY,
|
||||
"name" TEXT NOT NULL UNIQUE
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i,)) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO weaponcategory(name) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating weaponcategory: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_movement(data, conn):
|
||||
table = """
|
||||
CREATE TABLE movement (
|
||||
movement_id INTEGER PRIMARY KEY,
|
||||
"name" TEXT UNIQUE NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i,)) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO movement(name) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating movement: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_frequency(data, conn):
|
||||
table = """
|
||||
CREATE TABLE frequency (
|
||||
freq_id INTEGER PRIMARY KEY,
|
||||
freq_descr TEXT NOT NULL UNIQUE
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i,)) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO frequency(freq_descr) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating frequency: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_alignment(data, conn):
|
||||
print(data)
|
||||
table = """
|
||||
CREATE TABLE alignment (
|
||||
alignment_id INTEGER PRIMARY KEY,
|
||||
"name" TEXT UNIQUE NOT NULL, -- 'Lawful Good'
|
||||
abbr TEXT UNIQUE NOT NULL -- 'LG'
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i['name'], i['abbr']))
|
||||
|
||||
stmt = "INSERT INTO alignment(name, abbr) VALUES (?,?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
print("Error creating alignment")
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_langrarity(data, conn):
|
||||
table = """
|
||||
CREATE TABLE langrarity (
|
||||
rarity_id INTEGER PRIMARY KEY,
|
||||
rarity_name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i,)) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO langrarity(rarity_name) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating langrarity: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
def do_actioncost(data, conn):
|
||||
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):
|
||||
table = """
|
||||
CREATE TABLE abilityscore (
|
||||
abilityscore_id INTEGER PRIMARY KEY,
|
||||
flag_rep INTEGER NOT NULL,
|
||||
short_name TEXT NOT NULL UNIQUE,
|
||||
long_name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i['flag_rep'], i['short_name'], i['long_name']))
|
||||
|
||||
stmt = "INSERT INTO abilityscore (flag_rep, short_name, long_name) VALUES (?,?,?)"
|
||||
try:
|
||||
conn.executemany(stmt,inp_data)
|
||||
except:
|
||||
print("Error creating abilityscore")
|
||||
else:
|
||||
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__":
|
||||
main()
|
|
@ -0,0 +1,106 @@
|
|||
---
|
||||
abilityscore:
|
||||
- flag_rep: 1
|
||||
short_name: STR
|
||||
long_name: Strength
|
||||
- flag_rep: 2
|
||||
short_name: DEX
|
||||
long_name: Dexterity
|
||||
- flag_rep: 4
|
||||
short_name: CON
|
||||
long_name: Constitution
|
||||
- flag_rep: 8
|
||||
short_name: INT
|
||||
long_name: Intelligence
|
||||
- flag_rep: 16
|
||||
short_name: Wis
|
||||
long_name: Wisdom
|
||||
- flag_rep: 32
|
||||
short_name: CHA
|
||||
long_name: Charisma
|
||||
- flag_rep: 64
|
||||
short_name: Free1
|
||||
long_name: Free 1
|
||||
- flag_rep: 128
|
||||
short_name: Free2
|
||||
long_name: Free 2
|
||||
actioncost:
|
||||
- name: Varies
|
||||
abbr: varies
|
||||
- name: Single Action
|
||||
abbr: 1
|
||||
- name: Two Actions
|
||||
abbr: 2
|
||||
- name: Three Actions
|
||||
abbr: 3
|
||||
- name: Free Action
|
||||
abbr: free
|
||||
- name: Reaction
|
||||
abbr: reaction
|
||||
alignment:
|
||||
- name: Lawful Good
|
||||
abbr: LG
|
||||
- name: Neutral Good
|
||||
abbr: NG
|
||||
- name: Chaotic Good
|
||||
abbr: CG
|
||||
- name: Lawful Neutral
|
||||
abbr: LN
|
||||
- name: True Neutral
|
||||
abbr: N
|
||||
- name: Chaotic Neutral
|
||||
abbr: CN
|
||||
- name: Lawful Evil
|
||||
abbr: LE
|
||||
- name: Neutral Evil
|
||||
abbr: NE
|
||||
- name: Chaotic Evil
|
||||
abbr: CE
|
||||
frequency:
|
||||
- once per round
|
||||
- once per turn
|
||||
- once per minute
|
||||
- once every 10 minutes
|
||||
- once per hour
|
||||
- once per day
|
||||
lang_rarity:
|
||||
- Common
|
||||
- Uncommon
|
||||
- Secret
|
||||
movement:
|
||||
- Land
|
||||
- Burrow
|
||||
- Climb
|
||||
- Fly
|
||||
- Swim
|
||||
size:
|
||||
- name: Tiny
|
||||
space_in_ft: 4
|
||||
reach_tall_ft: 0
|
||||
reach_long_ft: 0
|
||||
- name: Small
|
||||
space_in_ft: 5
|
||||
reach_tall_ft: 5
|
||||
reach_long_ft: 5
|
||||
- name: Medium
|
||||
space_in_ft: 5
|
||||
reach_tall_ft: 5
|
||||
reach_long_ft: 5
|
||||
- name: Large
|
||||
space_in_ft: 10
|
||||
reach_tall_ft: 10
|
||||
reach_long_ft: 5
|
||||
- name: Huge
|
||||
space_in_ft: 15
|
||||
reach_tall_ft: 15
|
||||
reach_long_ft: 10
|
||||
- name: Gargantuan
|
||||
space_in_ft: 20
|
||||
reach_tall_ft: 20
|
||||
reach_long_ft: 15
|
||||
weaponcategory:
|
||||
- Unarmed
|
||||
- Simple
|
||||
- Martial
|
||||
- Advanced
|
||||
...
|
Loading…
Reference in New Issue