xivind / velo-supervisor-2000

Program to monitor bicycle service intervals
2 stars 0 forks source link

Create API call to get rides from Strava #10

Closed xivind closed 3 months ago

xivind commented 4 months ago

Sample code from https://www.hainke.ca/index.php/2018/08/23/using-the-strava-api-to-retrieve-activity-data/

Pseudo: Call Strava API page 1 - 200 entries If id exist, update, if not insert Increment page and repeat Stop API calls when page returns empty

`page = 1

while True:

# get page of activities from Strava
r = requests.get(url + '?' + access_token + '&per_page=50' + '&page=' + str(page))
r = r.json()

# if no results then exit loop
if (not r):
    break

# otherwise add new data to dataframe
for x in range(len(r)):
    activities.loc[x + (page-1)*50,'id'] = r[x]['id']
    activities.loc[x + (page-1)*50,'type'] = r[x]['type']

# increment page
page += 1`
xivind commented 3 months ago

Ready, gets either last 200 rides or all rides, based on supplied arg.