Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marknotfound/84da817443e54b54b27543b0dc8a1609 to your computer and use it in GitHub Desktop.
Save marknotfound/84da817443e54b54b27543b0dc8a1609 to your computer and use it in GitHub Desktop.
Workout list generator for defy calendar hack
import csv
import yaml
"""
convert yaml to json
python -c "import sys, yaml, json; json.dump(yaml.load(sys.stdin, Loader=yaml.FullLoader), sys.stdout, indent=4)" < public/plans/yaml/higdon_int_half2.yaml > public/plans/json/higdon_int_half2.json
"""
"""
Grab a CSV from the higdon site by exporting the html table, then use this script to parse
the CSV into workouts
"""
def distance_title(mi, suffix) -> str:
mi = float(mi)
km = mi * 1.60934
return f"{{{mi}:{km:.1f}}} {suffix}"
def print_csv_file(file_path):
try:
with open(file_path, newline="") as csvfile:
csv_reader = csv.reader(csvfile)
weeks = []
for row in csv_reader:
if row[0] == "Week":
continue
workouts = []
for value in row[1:]: # skip week column
workout = {}
if value.endswith("mi run"):
workout["title"] = distance_title(value.split(" ")[0], "run")
workout["distance"] = float(value.split(" ")[0])
elif value.endswith("mi pace"):
workout["title"] = distance_title(value.split(" ")[0], "pace")
workout["distance"] = float(value.split(" ")[0])
else:
workout["title"] = value
workouts.append(workout)
weeks.append({"workouts": workouts})
print(yaml.dump(weeks))
except FileNotFoundError:
print(f"File not found: {file_path}")
except Exception as e:
print(f"Error occurred: {e}")
csv_file_path = "/Users/mark/Downloads/higdonhmint2.csv"
print_csv_file(csv_file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment