paceboard/scripts/add-run.py

110 lines
3.2 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:
2021-06-27 19:45:49 +01:00
print("Add a category first!")
2021-06-25 18:35:35 +01:00
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
2021-06-28 03:40:15 +01:00
# Handle input of tk_run_runner and tk_run_verifier
2021-06-26 04:59:37 +01:00
tk_run_runner = input("Runner: ").replace('"', "")
tk_run_verifier = input("Verifier: ").replace('"', "")
2021-06-25 18:35:35 +01:00
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]
2021-06-27 20:08:08 +01:00
print(f"{index + 1} - {categoriesNew[index][displayName]}")
2021-06-25 18:35:35 +01:00
index += 1
try:
try:
rawCategoryInput = input("Your pick: ")
except KeyboardInterrupt:
os._exit(1)
2021-06-27 20:08:08 +01:00
categoryInput = int(rawCategoryInput) - 1
2021-06-25 18:35:35 +01:00
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:
2021-06-27 19:13:06 +01:00
print("Not a valid choice!")
2021-06-25 18:35:35 +01:00
print(f"You picked - {categoriesNew[categoryInput][displayName]}\n")
## End of: Handle input of tk_run_category_dashname ##
2021-06-28 03:40:15 +01:00
# Handle input of tk_run_date, tk_run_description, and tk_run_link
2021-06-26 04:59:37 +01:00
tk_run_date = input("Date (format - MM/DD/YYYY): ").replace('"', "")
tk_run_description = input("Description: ").replace('"', "")
2021-06-25 18:35:35 +01:00
tk_run_link = input("Recording link (format - https://foo.bar): ")
2021-06-28 03:40:15 +01:00
# Define run dictionary
2021-06-25 18:35:35 +01:00
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,
}
2021-06-28 03:40:15 +01:00
# Write to csv
2021-06-25 18:35:35 +01:00
util_csv.dictWriter("../csv/runs.csv", runDict, "a")
print(
2021-06-27 20:08:08 +01:00
f"\n{divider}\n\nAdded run! If you made a mistake, you can manually edit csv/runs.csv"
2021-06-25 18:35:35 +01:00
)