got sources working with yaml to sql

source_entries
James Miller 2019-11-11 21:39:45 -06:00
parent 7187c663c2
commit 39f1a25704
2 changed files with 85 additions and 2 deletions

View File

@ -12,7 +12,6 @@ def main():
# 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 a DB conn # Get a DB conn
conn = get_db_conn() conn = get_db_conn()
# call the functions to input to SQL # call the functions to input to SQL
@ -28,9 +27,54 @@ def main():
# move on to traits # move on to traits
with open('traits.yaml') as yl: with open('traits.yaml') as yl:
data = yaml.full_load(yl) data = yaml.full_load(yl)
# pprint.pprint(data)
do_traits(data, conn) # does both trait types and traits do_traits(data, conn) # does both trait types and traits
# move on to sources
with open('sources.yaml') as yl:
data = yaml.full_load(yl)
do_sources(data, conn)
def do_sources(data, conn):
table = """
CREATE TABLE sources (
sources_id INTEGER PRIMARY KEY,
isbn TEXT,
pzocode TEXT,
full_name TEXT NOT NULL UNIQUE,
short_name TEXT NOT NULL UNIQUE,
abbr TEXT NOT NULL UNIQUE,
descr TEXT NOT NULL,
release_date TEXT NOT NULL, -- in YYYY-MM-DD format
is_first_party BOOLEAN NOT NULL,
ogl_copyright_block TEXT NOT NULL
);
"""
c = conn.cursor()
c.execute(table)
inp_data = []
for i in data['source']:
inp_data.append((i['isbn'],
i['pzocode'],
i['full_name'],
i['short_name'],
i['abbr'],
i['descr'],
i['release_date'],
i['is_first_party'],
i['ogl_copyright_block']))
stmt = "INSERT INTO sources (isbn, pzocode, full_name, short_name, abbr, descr, release_date, is_first_party, ogl_copyright_block) VALUES (?,?,?,?,?,?,?,?,?)"
try:
conn.executemany(stmt,inp_data)
except sqlite3.Error as e:
print("Error creating sources: {}".format(e))
except:
print("Error creating sources something other than sqlite3 error")
else:
conn.commit()
def do_traits(data, conn): def do_traits(data, conn):
# create the two tables # create the two tables
table = """ table = """

View File

@ -0,0 +1,39 @@
source:
- full_name: Pathfinder Core Rulebook (Second Edition)
isbn: 978-1-64078-168-9
pzocode: PZO2101
short_name: Core Rulebook
abbr: CRB
descr: Volume containing the rules core rules for players and Game Masters
release_date: 2019-08-01
is_first_party: true
ogl_copyright_block: "Open Game License v.1.0a (c) 2000, Wizards of the Coast, Inc.; System Reference Document (c) 2000, Wizards of the Coast, Inc.; Authors: Jonathan Tweet, Monte Cook, and Skip Williams, based on material by E. Gary Gygax and Dave Arneson. Pathfinder Core Rulebook (Second Edition) (c) 2019, Paizo, Inc.; Designers: Logan Bonner, Jason Bulmahn, Stephen Radney-MacFarland, and Mark Seifter."
- full_name: Pathfinder Bestiary (Second Edition)
isbn: 978-1-64078-170-2
pzocode: PZO2102
short_name: Bestiary
abbr: BST1
descr: Volume containing monster stat blocks and rules primarily for Game Masters
release_date: 2019-08-01
is_first_party: true
ogl_copyright_block: "Daemon, Guardian from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Ian McDowall. Dark Creeper from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Rik Shepard. Dark Stalker from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Simon Muth. Dragon, Faerie from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Brian Jaeger and Gary Gygax. Genie, Marid from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Gary Gygax. Mite from the Tome of Horrors Complete © 2011, Necromancer Games, Inc., published and distributed by Frog God Games; Author: Scott Greene, based on original material by Ian Livingstone and Mark Barnes. Pathfinder Bestiary (Second Edition) © 2019, Paizo Inc.; Authors: Alexander Augunas, Logan Bonner, Jason Bulmahn, John Compton, Paris Crenshaw, Adam Daigle, Eleanor Ferron, Leo Glass, Thurston Hillman, James Jacobs, Jason Keeley, Lyz Liddell, Ron Lundeen, Robert G. McCreary, Tim Nightengale, Stephen Radney-MacFarland, Alex Riggs, David N. Ross, Michael Sayre, Mark Seifter, Chris S. Sims, Jeffrey Swank, Jason Tondro, Tonya Woldridge, and Linda Zayas-Palmer."
- full_name: "Pathfinder Adventure: The Fall of Plaguestone"
isbn: 978-1-64078-174-0
pzocode: PZO9555
short_name: The Fall of Plaguestone
abbr: TFoP
# TODO Fix description
descr: TODO
release_date: 2019-08-01
is_first_party: true
ogl_copyright_block: "Pathfinder Adventure: The Fall of Plaguestone © 2019, Paizo Inc.; Author: Jason Bulmahn."
- full_name: "Age of Ashes Player's Guide"
isbn: null
pzocode: PZO9000-25E
short_name: "Age of Ashes Player's Guide"
abbr: AoAPG
# TODO Fix description
descr: "Player's Guide for the Age of Ashes Adventure Path"
release_date: 2019
is_first_party: true
ogl_copyright_block: "Age of Ashes Player''s Guide © 2019, Paizo Inc.; Authors: James Jacobs with Amanda Hamon."