A static dashboard showing yearly cycling stats from Strava. Fetches ride data via the Strava API, aggregates it by year, and generates a single-page HTML dashboard with an interactive chart and table in metric and US units.
See an example using axoplasm’s data at stradeviola.axoplasm.com.
-
Create a Strava API application and set the redirect URI to
http://localhost:8000/callback. -
Create a
.envfile:STRAVA_CLIENT_ID=your_id STRAVA_CLIENT_SECRET=your_secret -
Install dependencies:
$ python3 -m venv venv $ source venv/bin/activate (venv) $ pip install -r requirements.txt -
Test the connection to the API by running
main.py. This will fetch the 10 most recent cycling activities in your Strava profile.(venv) $ python main.py
-
Run the build script. On first run it will open a browser for Strava OAuth, then fetch all activities:
(venv) $ python build_site.py
On subsequent runs it only fetches the current year's activities and updates
public/data.jsonif anything changed.
Serve the public/ directory with any static file server. For example:
(venv) python -m http.server -d publicauth.py— Strava OAuth flow and token management (saved to.tokens.json)build_site.py— Fetches ride data, aggregates by year, writespublic/data.jsonyearly_stats.py— CLI script that prints yearly stats to the terminalmain.py— CLI script that prints recent activitiespublic/index.html— Static dashboard with interactive chart and tablepublic/data.json— Generated data file (not checked in).env— Environment variables (not checked in). See Setup, above.tokens.json— Local copy of auth token (not checked in)public/css/*— reference css files. Selectors from these files can be copied into the<style>tag inindex.html
To keep the data fresh on a server, run build_site.py periodically, for example with a cron job that executes every hour:
0 * * * * /path/to/stradeviola/venv/bin/python /path/to/stradeviola/build_site.py >> /var/log/stradeviola.log 2>&1
The initial OAuth flow must be done interactively. After that, token refresh is automatic.