During the past few months I’ve started to track my biking and running on Strava, partly because I’m training for some events, and partly just for fun – coding fun – now I have some interesting data to visualize!
The bulk of the coding I basically did in conversation with ChatGPT, after I’d decided to use python and the stravalib, however, the main design choice to be made was around Strava’s API constraints which are currently:
- 100 requests every 15 minutes, 1,000 requests daily
I need to make one API call to get the the id numbers of all my activities in the past 365 days, but then I’d have to make another API call per activity to get the details including the ‘best efforts’ which was what I wanted to show which activities gave me my best times in running 5k, 10k and half marathon. So far in 6 months I’m already at almost 80 activities so would be really close to the 15 minute limit with just the info for one page – so I’d need to cache the results of API calls for subsequent page views.
I initially started off using streamlit, which is really easy to use and looks good out of the box, and I wanted to try the free streamlit hosting. However, streamlit only caches per user session, so I’d need to implement my own caching and save it in a different location like S3 for streamlit to pull in. It sounded too much effort to do it this way – so I went for what is fast becoming my default for basically free hosting – Cloudflare pages, connected to a github repo, and deploying whatever is in the /output folder.
My github actions could run every day as a cron job with the one API call to get all the past 365 days activities, and I could cache the details of each activity back to the github repo, and use these for subsequent days, meaning I’m only really going to be doing 2 API calls per day, one to check all the activities, and another to get the details of the latest activity (unlikely that I’d do more than one in a day!). The python code is quite fast to run and only uses Jinja2 templating, stravalib and dotenv outside of the normal packages, so it is a good candidate to run inside github actions.
The only remaining thing to do was to find a decent html template to make it look good (Sneat Bootstrap HTML Admin Template) and add some YouTube 3D map videos of some of my routes using this great little app: https://www.rumbo.world/home. The last thing I want to ads is a chart showing my distance per month for running and biking – but other than that I’m pretty happy with this little project!
The github repo is staying private to hide my cached data, but here is a gist for the github actions workflow and the python file which generates the site:
Leave a Reply