From 27b8315ab089180876b890a06b8091e09f99ffc4 Mon Sep 17 00:00:00 2001 From: Zachary Tatlock Date: Wed, 3 Apr 2024 20:59:57 -0700 Subject: [PATCH] start experimenting with generating yaml from route db --- _data/.gitignore | 1 + _data/route-db-invariants.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 _data/.gitignore diff --git a/_data/.gitignore b/_data/.gitignore new file mode 100644 index 0000000..4d9bd8c --- /dev/null +++ b/_data/.gitignore @@ -0,0 +1 @@ +route-db.yaml diff --git a/_data/route-db-invariants.py b/_data/route-db-invariants.py index ea7e509..666c72b 100644 --- a/_data/route-db-invariants.py +++ b/_data/route-db-invariants.py @@ -1,7 +1,7 @@ import csv import os -FIELDS = ['id', 'name', 'dist', 'elev', 'start', 'end', 'type', 'map'] +FIELDS = ['id', 'name', 'start', 'dist', 'elev', 'end', 'type', 'map'] TYPES = ['Loop', 'P2P', 'OB'] LOCS = [ 'Beacon', @@ -21,6 +21,7 @@ # route-db.csv lives in the same directory as this script data_dir = os.path.dirname(os.path.realpath(__file__)) csv_path = os.path.join(data_dir, 'route-db.csv') +yaml_path = os.path.join(data_dir, 'route-db.yaml') gpx_dir = os.path.join(data_dir, 'gpx') warnings = False @@ -94,3 +95,17 @@ def check_route(route): writer.writeheader() for route in routes: writer.writerow(route) + +# output yaml version as well +with open(yaml_path, 'w') as f: + f.write('# AUTOGENERATED - DO NOT EDIT\n\n') + for route in routes: + f.write(f"- id: {route['id']}\n") + f.write(f" name: \"{route['name']}\"\n") + f.write(f" start: \"{route['start']}\"\n") + f.write(f" dist: {route['dist']}\n") + f.write(f" elev: {route['elev']}\n") + f.write(f" end: \"{route['end']}\"\n") + f.write(f" type: \"{route['type']}\"\n") + f.write(f" map: \"{route['map']}\"\n") + f.write('\n') \ No newline at end of file