Skip to content

Commit

Permalink
move route db out into main site
Browse files Browse the repository at this point in the history
  • Loading branch information
ztatlock committed May 24, 2024
1 parent 4c4b17a commit f1911bb
Show file tree
Hide file tree
Showing 148 changed files with 27 additions and 29 deletions.
23 changes: 10 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
DATA = _data
ROUTES = $(DATA)/routes.yml
ROUTE_DB_CSV = $(DATA)/route-db.csv
ROUTE_DB_YML = $(DATA)/route-db.yml
SCHEDULE = $(DATA)/schedule.yml
ROUTES = routes
ROUTES_CSV = $(ROUTES)/db.csv

DATA = _data
ROUTES_YML = $(DATA)/routes.yml
SCHEDULE = $(DATA)/schedule.yml

.PHONY: all build serve publish clean

all: build

$(ROUTE_DB_YML): _bin/route-db.py $(ROUTE_DB_CSV)
python3 $< $(DATA)

$(ROUTES): $(ROUTE_DB_YML)
# TODO jekyll needs a .yml that has a different name than the .csv
cp $(ROUTE_DB_YML) $(ROUTES)
$(ROUTES_YML): _bin/route-db.py $(ROUTES_CSV)
python3 $< $(PWD)

rcc.ics: _bin/mkical.py $(SCHEDULE) $(ROUTES)
rcc.ics: _bin/mkical.py $(SCHEDULE) $(ROUTES_YML)
python3 $<

build: rcc.ics
Expand All @@ -25,5 +22,5 @@ serve: rcc.ics
watchy -w _config.yml -- bundle exec jekyll serve --watch --drafts --host=0.0.0.0

clean:
rm -f $(ROUTES) $(ROUTE_DB_YML)
rm -f $(ROUTES_YML)
rm -rf _site/ .jekyll-cache/ rcc.ics rcc_weekends.ics
33 changes: 17 additions & 16 deletions _bin/route-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def warn(msg):
def warn_rc(route, msg):
warn(f"route {route['id']}: {msg}")

def check_route(route, gpx_dir):
def check_route(route, routes_dir):
# all fields set
for field in FIELDS:
if field not in route:
Expand Down Expand Up @@ -98,29 +98,25 @@ def check_route(route, gpx_dir):
warn_rc(route, f"invalid deprecated status '{route['deprecated']}'")

# every route has a gpx
gpx_path = os.path.join(gpx_dir, route['id']) + '.gpx'
gpx_path = os.path.join(routes_dir, route['id']) + '.gpx'
if not os.path.isfile(gpx_path):
warn_rc(route, f"no GPX file at '{gpx_path}'")

def main():
# get args
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <data_dir>")
print(f"Usage: {sys.argv[0]} <RCR repo root>")
exit(1)
repo_root = sys.argv[1]

data_dir = sys.argv[1]
if not os.path.isdir(data_dir):
print(f"Error: no such directory '{data_dir}'")
routes_dir = os.path.join(repo_root, 'routes')
if not os.path.isdir(routes_dir):
print(f"Error: no such directory '{routes_dir}'")
exit(1)

csv_path = os.path.join(data_dir, 'route-db.csv')
csv_path = os.path.join(routes_dir, 'db.csv')
if not os.path.isfile(csv_path):
print(f"Error: no route-db.csv at '{csv_path}'")
exit(1)

gpx_dir = os.path.join(data_dir, 'gpx')
if not os.path.isdir(gpx_dir):
print(f"Error: no gpx directory at '{gpx_dir}'")
print(f"Error: no db.csv at '{csv_path}'")
exit(1)

# read routes
Expand All @@ -137,7 +133,7 @@ def main():

# check every route
for route in routes:
check_route(route, gpx_dir)
check_route(route, routes_dir)

# bail if any warnings
if warnings:
Expand All @@ -154,8 +150,13 @@ def main():
for route in routes:
writer.writerow(route)

# output yaml version as well
yml_path = os.path.join(data_dir, 'route-db.yml')
# output yaml version to _data dir
data_dir = os.path.join(repo_root, '_data')
if not os.path.isdir(data_dir):
print(f"Error: no such directory '{data_dir}'")
exit(1)

yml_path = os.path.join(data_dir, 'routes.yml')
with open(yml_path, 'w') as f:
f.write('# AUTOGENERATED - DO NOT EDIT\n\n')
for route in routes:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f1911bb

Please sign in to comment.