paceboard/scripts/add-run.py

107 lines
3 KiB
Python
Raw Normal View History

2021-06-25 18:55:15 +01:00
#!/usr/bin/env python3
2021-06-25 18:35:35 +01:00
### Script for adding a new category. Handles adding data to config.csv.
from utils import csv as util_csv
import os
## Check to see if there's at least one category ##
categoriesOld = util_csv.dictReaderMultiRow(
"../csv/categories.csv", "tk_category_dashname"
)
if len(categoriesOld.keys()) == 0:
print("Add a category first (using scripts/add-category.py)")
os._exit(1)
2021-06-26 04:05:19 +01:00
## End of: Check to see if there's at least one category ##
2021-06-25 18:35:35 +01:00
divider = "----------"
print(
2021-06-26 04:05:19 +01:00
f"\nWe'll ask for the runner, verifier, run duration (time), category, run date, category, description of, and recording link of the new run.\n\n{divider}\n"
2021-06-25 18:35:35 +01:00
)
tk_run_id = 1
existingRuns = util_csv.dictReaderMultiRow("../csv/runs.csv", "tk_run_id")
for id in existingRuns:
tk_run_id = int(id) + 1
tk_run_runner = input("Runner: ")
tk_run_verifier = input("Verifier: ")
2021-06-26 04:05:19 +01:00
## Handle input of tk_run_duration ##
doneDurationInput = False
while not doneDurationInput:
tk_run_duration = input("Duration (format - HH:MM:SS): ")
values = tk_run_duration.split(":")
if len(values) == 3:
try:
for value in values:
test = float(value)
doneDurationInput = True
except:
print("Invalid input!")
else:
print("Invalid input!")
## End of: Handle input of tk_run_duration ##
2021-06-25 18:35:35 +01:00
## Handle input of tk_run_category_dashname ##
doneCategoryInput = False
displayName = "tk_category_name"
while not doneCategoryInput:
print("\nCategory (input a number)")
index = 0
categoriesNew = {}
for category in categoriesOld:
categoriesNew[index] = categoriesOld[category]
print(f"{index} - {categoriesNew[index][displayName]}")
index += 1
try:
try:
rawCategoryInput = input("Your pick: ")
except KeyboardInterrupt:
os._exit(1)
categoryInput = int(rawCategoryInput)
if categoryInput <= index:
try:
tk_run_category_dashname = categoriesNew[categoryInput][
"tk_category_dashname"
]
doneCategoryInput = True
except:
print("Not a valid choice!")
else:
print("Not a valid choice!")
except:
print("Not a number!")
print(f"You picked - {categoriesNew[categoryInput][displayName]}\n")
## End of: Handle input of tk_run_category_dashname ##
tk_run_date = input("Date (format - MM/DD/YYYY): ")
tk_run_description = input("Description: ")
tk_run_link = input("Recording link (format - https://foo.bar): ")
runDict = {
"tk_run_id": tk_run_id,
"tk_run_runner": tk_run_runner,
"tk_run_verifier": tk_run_verifier,
2021-06-26 04:05:19 +01:00
"tk_run_duration": tk_run_duration,
2021-06-25 18:35:35 +01:00
"tk_run_category_dashname": tk_run_category_dashname,
"tk_run_date": tk_run_date,
"tk_run_description": tk_run_description,
"tk_run_link": tk_run_link,
}
util_csv.dictWriter("../csv/runs.csv", runDict, "a")
print(
f"\n{divider}\n\nAdded run! If you made a mistake, you can manually edit csv/runs.csv\n"
)