Skip to content

Instantly share code, notes, and snippets.

@squeezer44
Created November 9, 2021 22:17
Show Gist options
  • Save squeezer44/c89114f884e37406a301b1f77be10bfe to your computer and use it in GitHub Desktop.
Save squeezer44/c89114f884e37406a301b1f77be10bfe to your computer and use it in GitHub Desktop.
# -------------
# Imports
import pandas as pd
pd.set_option("display.max_columns", 100)
import pprint
from stravalib.client import Client
# -------------
# Variables
MY_STRAVA_CLIENT_ID, MY_STRAVA_CLIENT_SECRET = open('../poc_code/assets/client.secret').read().strip().split(',')
# -------------
# list athletes activities
client = Client(access_token='I-AM-THE-TOKEN')
activities = client.get_activities(limit=1000) # get the list
# create a list with columns we want to see the related values
data = []
my_cols =['name',
'start_date_local',
'type',
'distance',
'moving_time',
'elapsed_time',
'total_elevation_gain',
'elev_high',
'elev_low',
'average_speed',
'max_speed',
'average_heartrate',
'max_heartrate',
'start_latitude',
'start_longitude']
for activity in activities:
my_dict = activity.to_dict()
data.append([activity.id] + [my_dict.get(x) for x in my_cols])
# Add id to the beginning of the columns, used when selecting a specific activity
my_cols.insert(0, 'id')
# put the data into a dataframe
df = pd.DataFrame(data, columns=my_cols)
# print the first and the last activity
print(df.iloc[0])
print(df.iloc[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment