This python application is made to post weekly running stats from a Strava club to a Slack channel.
Clone the Repository:
git clone https://github.com/fleinen/Weekly-Strava-Stats-in-Slack.git
cd Weekly-Strava-Stats-in-Slack
Install the requirements:
# Ensure you have poetry installed
pip install poetry
poetry install
Currently, the application uses the Strava widget to fetch the weekly running stats. To get the widget URL:
- Go to https://www.strava.com/ and navigate to your club's page
- Click on "Share Club Runs"
- In the text box showing the code for the Summary Widget, copy the iframe's
src
url - This url must be set as an environment variable with the key
STRAVA_WIDGET_URL
which can be set in the.env
file.
Create the app:
- Go to https://api.slack.com/apps
- Click "Create New App"
- Choose "From scratch"
- Name the app (e.g., "Weekly Strava Running Stats")
- Select workspace
Bot Permissions:
- Go to "OAuth & Permissions" in left sidebar
- Under "Bot Token Scopes", add:
- chat:write
Install App to Workspace
- Go to "OAuth & Permissions"
- Click "Install to Workspace"
- Authorize the app
- Get Tokens
- Copy "Bot User OAuth Token" (starts with xoxb-)
- The token must be set as an environment variable with the key
SLACK_BOT_TOKEN
which can be set in the.env
file.
After installing the app to your workspace, open Slack. In the channel where you want the bot to post:
- Click the channel name at the top
- Scroll down and copy the channel ID (starts with C)
- The channel ID must be set as an environment variable with the key
SLACK_CHANNEL
which can be set in the.env
file. - Select "Integrations"
- Click "Add apps" and search for your app's name
The application provides two commands which should be working by now:
fetch-strava-stats
to fetch the weekly running stats from Strava.post-last-weeks-stats
to post the stats to a Slack channel. Both jobs can be configured to run on a schedule using a cron job:
To download data every day at 11:55 PM and post the stats every Monday at 8:30 AM, run crontab -e
in a terminal and add:
55 23 * * * cd /path/to/Weekly-Strava-Stats-in-Slack && poetry run weekly-strava-stats fetch-strava-stats
30 8 * * 1 cd /path/to/Weekly-Strava-Stats-in-Slack && poetry run weekly-strava-stats post-last-weeks-stats
There will be a quote at the end of every message. If a Groq API key is provided, it will be a fictional quote from commenting on the Strava stats. If not, it will be a random quote from a hardcoded list.
You can generte an API key here. The key must be set as an environment variable with the key GROQ_API_KEY
which can be set in the .env
file.
By default, the predefined prompts from the file src/weeklt_strava_stats/data/quote_prompts.csv
will be used. If you want to use your own prompts, you can set the environment variable QUOTE_PROMPTS_PATH
in the .env
file.
If you want to include a link to the Strava club in the message, you can set the environment variable STRAVA_CLUB_URL
in the .env
file.