Skip to content

Instantly share code, notes, and snippets.

@chrisfleming
Last active June 12, 2018 23:43
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 chrisfleming/5ddbb6322076c916e45b344cb2f4418b to your computer and use it in GitHub Desktop.
Save chrisfleming/5ddbb6322076c916e45b344cb2f4418b to your computer and use it in GitHub Desktop.
Getting a leaderboard from strava - quick and dirty, adjust as needed:
#!/usr/bin/env python
# Set access_toke, pages, segement and timeframe below
# To run install dependencies:
# pip install --user stravalib
# pip install --user kitchen
import time
from kitchen.text.converters import getwriter
import sys
from stravalib import Client
access_token= # Your access token, this is a good guide: http://yizeng.me/2017/01/11/get-a-strava-api-access-token-with-write-permission/
segment=17931346
timeframe=None # None, this_year, this_month, this_week or today
UTF8Writer = getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
client = Client(access_token)
page=1
while page:
leaderboard = client.get_segment_leaderboard(segment, page=page, timeframe=timeframe)
for i in range(0, 9):
try:
print u"%s,%s,%s,%s,%s" % (leaderboard[i].rank,
leaderboard[i].athlete_name,
leaderboard[i].start_date_local,
leaderboard[i].elapsed_time,
leaderboard[i].moving_time)
except IndexError:
sys.exit()
page+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment