Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active August 7, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5b526522c704d8ad4e7a3bdb8063b072 to your computer and use it in GitHub Desktop.
Save tmcw/5b526522c704d8ad4e7a3bdb8063b072 to your computer and use it in GitHub Desktop.
Strava Bitbar plugin

A bitbar plugin for Strava. Shows you how many miles you've run so far this year.

#!/usr/bin/python
# coding=utf8
#
# <bitbar.author>Tom MacWright</bitbar.author>
# <bitbar.author.github>tmcw</bitbar.author.github>
# <bitbar.title>Get your mileage from Strava</bitbar.title>
# <bitbar.version>1.0</bitbar.version>
# <bitbar.desc>Shows this week and this year’s numbers</bitbar.desc>
# <bitbar.image>http://i.imgur.com/JtguThL.png</bitbar.image>
# <bitbar.dependencies>python</bitbar.dependencies>
# <bitbar.abouturl>https://macwright.org/</bitbar.abouturl>
import requests
from pprint import pprint
# Get an access token at https://www.strava.com/settings/api
# Get your id as the number at the end of the URL of your Strava profile
id = "YOUR_ID"
access_token = "YOUR_ACCESS_TOKEN"
headers = {"Authorization":"Bearer %s" % access_token}
resp = requests.get("https://www.strava.com/api/v3/athletes/%s/stats?page=&per_page=" % id, headers=headers).json()
print "{:.0f}mi".format(resp['ytd_run_totals']['distance'] / 1609.34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment