Last active
June 12, 2018 23:43
-
-
Save chrisfleming/5ddbb6322076c916e45b344cb2f4418b to your computer and use it in GitHub Desktop.
Getting a leaderboard from strava - quick and dirty, adjust as needed:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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