First working helper script

This commit is contained in:
Zachary Talis 2021-06-27 14:45:49 -04:00
parent 70d3d14b59
commit a99180ce9f
2 changed files with 28 additions and 10 deletions

View file

@ -4,27 +4,37 @@
import subprocess, os import subprocess, os
import scripts.utils.csv as util_csv import scripts.utils.csv as util_csv
# If no setup completed, run setup script os.chdir("scripts/")
config = util_csv.dictReaderFirstRow("csv/config.csv") cwd = os.getcwd()
if config == {}:
subprocess.call("scripts/setup.py", shell=True)
doneOptionInput = False
def generate():
"""Regenerate site"""
runIdName = "tk_run_id"
categoryIdName = "tk_category_dashname"
runs = util_csv.dictReaderMultiRow("../csv/runs.csv", runIdName)
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
config = util_csv.dictReaderFirstRow("../csv/config.csv")
print(len(config))
print(len(categories))
print(len(runs))
if len(config) != 0 and len(categories) != 0 and len(runs) != 0:
subprocess.call(cwd + "/generate.py", shell=True)
def optionSetup(): def optionSetup():
"""Reconfigure site details""" """Reconfigure site details"""
print("hi") subprocess.call(cwd + "/setup.py", shell=True)
def optionAddCategory(): def optionAddCategory():
"""Add category""" """Add category"""
print("hello") subprocess.call(cwd + "/add-category.py", shell=True)
def optionAddRun(): def optionAddRun():
"""Add run""" """Add run"""
print("cool") subprocess.call(cwd + "/add-run.py", shell=True)
def optionQuit(): def optionQuit():
@ -32,8 +42,16 @@ def optionQuit():
os._exit(1) os._exit(1)
# If no setup completed, run setup script
config = util_csv.dictReaderFirstRow("../csv/config.csv")
if len(config) == 0:
optionSetup()
generate()
# Set options (as defined earlier)
options = [optionSetup, optionAddCategory, optionAddRun, optionQuit] options = [optionSetup, optionAddCategory, optionAddRun, optionQuit]
# Main loop
while True: while True:
key = "tk_game_name" key = "tk_game_name"
print(f"\n[ paceboard for {config[key]} ]") print(f"\n[ paceboard for {config[key]} ]")
@ -48,8 +66,8 @@ while True:
os._exit(1) os._exit(1)
optionInput = int(rawOptionInput) optionInput = int(rawOptionInput)
if 0 < optionInput <= len(options): if 0 < optionInput <= len(options):
print("")
options[optionInput - 1]() options[optionInput - 1]()
generate()
else: else:
print("Not a valid choice!") print("Not a valid choice!")
except: except:

View file

@ -10,7 +10,7 @@ categoriesOld = util_csv.dictReaderMultiRow(
"../csv/categories.csv", "tk_category_dashname" "../csv/categories.csv", "tk_category_dashname"
) )
if len(categoriesOld.keys()) == 0: if len(categoriesOld.keys()) == 0:
print("Add a category first (using scripts/add-category.py)") print("Add a category first!")
os._exit(1) os._exit(1)
## End of: Check to see if there's at least one category ## ## End of: Check to see if there's at least one category ##