MAJOR DIRECTORY OVERHAUL

bradl/monsters-adult-gold-dragon
James Miller 2020-04-25 01:37:42 -05:00
parent 71ed03b165
commit 34ef5a6025
138 changed files with 48 additions and 6 deletions

View File

@ -28,6 +28,25 @@ will fit into memory easily so performance issues aren't likely to be a problem.
Also, most use cases of this data will likely be read only, so the sqlite Also, most use cases of this data will likely be read only, so the sqlite
limitations on concurrent writes won't be an issue either. limitations on concurrent writes won't be an issue either.
## Stop yacking and tell me how to generate the database from the YAMl!
Ok!
You'll need a working python3 installation and the module `pyyaml` installed.
### To install pyyaml
Run the correct pip install command: `pip install pyyaml`. Depending on your
operating system, this might be `pip3` or `python3-pip` instead of `pip`.
### Generate the database
From the repository root, navigate to the `bin` directory with a `cd ./bin` and
then run `python3 gendb.py`. The code is not optimized for speed, so depending
on your system and disk I/O, it might take a minute or so. The output file is
currently a `tmp.db` in the repository root. You can then explore the db file
with `sqlite3 tmp.db` called from the repository root directory.
## Where we need the most help right now ## Where we need the most help right now
### Proofreading Spells.yaml ### Proofreading Spells.yaml

View File

@ -9,6 +9,9 @@ import os
def main(): def main():
# change directory to the data directory
os.chdir('../data/')
# gets all files with a yaml extension in the directory # gets all files with a yaml extension in the directory
yfiles = [] yfiles = []
for file in glob.glob("*.yaml"): for file in glob.glob("*.yaml"):

View File

@ -1,30 +1,48 @@
import sys
# the append makes python look in the repo dir for other python modules
sys.path.append('..')
import yaml import yaml
import sqlite3 import sqlite3
import os import os
import pprint import pprint
import sys from lib.gendb.basics import *
from lib.basics import * from lib.gendb import utils
import lib.utils as utils import pathlib
DBFILE = 'tmp.db' DBFILE = 'tmp.db'
DATA_PATH = "../data/yaml" # This is path relative to gendb.py DBOUTPUT_PATH = pathlib.Path().absolute().parent
DATA_PATH = pathlib.Path().absolute().parent / 'data'
def main(): def main():
print("DB output is in path: {}".format(DBOUTPUT_PATH))
print("Data is in path: {}".format(DATA_PATH))
# CHANGE TO DIR WHERE DB FILE IS OUTPUT
try:
os.chdir(DBOUTPUT_PATH)
except OSError as e:
print("{}".format(e))
# delete DBfile and run fresh # delete DBfile and run fresh
try: try:
os.remove(DBFILE) os.remove(DBFILE)
except OSError as e: except OSError as e:
print("{}".format(e)) print("No prior database file found to remove. Will create a new one. Error message: {}".format(e))
# Get a DB conn # Get a DB conn
try:
os.chdir(DBOUTPUT_PATH)
except OSError as e:
print("{}".format(e))
conn = utils.get_db_conn(DBFILE) conn = utils.get_db_conn(DBFILE)
pragma = "PRAGMA foreign_keys = ON;" pragma = "PRAGMA foreign_keys = ON;"
c = conn.cursor() c = conn.cursor()
c.execute(pragma) c.execute(pragma)
# change directory to where the data currently is relative to script # CHANGE DIRECTORY TO WHERE THE DATA CURRENTLY IS RELATIVE TO SCRIPT
try: try:
os.chdir(DATA_PATH) os.chdir(DATA_PATH)
except OSError as e: except OSError as e:

View File

@ -1,5 +1,6 @@
import yaml import yaml
import pprint import pprint
import os
def main(): def main():
@ -8,6 +9,7 @@ def main():
def standardize_monsters(): def standardize_monsters():
os.chdir('../data/')
with open('monsters.yaml', 'r') as f: with open('monsters.yaml', 'r') as f:
data = yaml.full_load(f) data = yaml.full_load(f)
goodset = set() goodset = set()

Some files were not shown because too many files have changed in this diff Show More