got ability scores populating

source_entries
James Miller 2019-11-11 16:08:55 -06:00
parent 3aff6367c2
commit 998f331bcc
2 changed files with 60 additions and 9 deletions

View File

@ -1,3 +1,61 @@
import yaml
import sqlite3
import os
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)
## 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)
# call the functions to input to SQL
do_abilityscore(data['abilityscore'], conn)
def do_abilityscore(data, conn):
print(data)
print(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()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -24,7 +24,6 @@ abilityscore:
- flag_rep: 128 - flag_rep: 128
short_name: Free2 short_name: Free2
long_name: Free 2 long_name: Free 2
---
actioncost: actioncost:
- name: Varies - name: Varies
abbr: varies abbr: varies
@ -38,7 +37,6 @@ actioncost:
abbr: free abbr: free
- name: Reaction - name: Reaction
abbr: reaction abbr: reaction
---
alignment: alignment:
- name: Lawful Good - name: Lawful Good
abbr: LG abbr: LG
@ -58,7 +56,6 @@ alignment:
abbr: NE abbr: NE
- name: Chaotic Evil - name: Chaotic Evil
abbr: CE abbr: CE
---
frequency: frequency:
- once per round - once per round
- once per turn - once per turn
@ -66,19 +63,16 @@ frequency:
- once every 10 minutes - once every 10 minutes
- once per hour - once per hour
- once per day - once per day
---
lang_rarity: lang_rarity:
- Common - Common
- Uncommon - Uncommon
- Secret - Secret
---
movement: movement:
- Land - Land
- Burrow - Burrow
- Climb - Climb
- Fly - Fly
- Swim - Swim
---
size: size:
- name: Tiny - name: Tiny
space_in_ft: 4 space_in_ft: 4
@ -104,10 +98,9 @@ size:
space_in_ft: 20 space_in_ft: 20
reach_tall_ft: 20 reach_tall_ft: 20
reach_long_Ft: 15 reach_long_Ft: 15
---
weapon_category: weapon_category:
- Unarmed - Unarmed
- Simple - Simple
- Martial - Martial
- Advanced - Advanced
--- ...