Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Peloton bulk download script
import requests
import pandas as pd
user = "user"
password = "password"
# authenticate to get user_id and session_id
authcall = requests.post("https://api.pelotoncycle.com/auth/login",
json = {"username_or_email": user, "password": password})
user_id = authcall.json()["user_id"]
session_id = authcall.json()["session_id"]
cookies = {"peloton_session_id": session_id}
# this is hacky...I know there are only 129 rides, so made limit 200
workouts_str = f"""https://api.pelotoncycle.com/api/user/{user_id}/workouts?joins=peloton.ride&limit=200&page=0&sort_by=-created"""
getallworkouts = requests.get(workouts_str, cookies = cookies)
workouts = getallworkouts.json()["data"]
workoutids = [x["id"] for x in workouts]
len(workouts)
# get workout summaries
workout_summaries = []
for w in workoutids:
w_str = f"""https://api.pelotoncycle.com/api/workout/{w}?joins=peloton,peloton.ride,peloton.ride.instructor,user"""
r = requests.get(w_str, cookies = cookies)
workout_summaries.append(r.json())
# parse workout summaries
summary_dfs = json_normalize(workout_summaries, sep="_")
summary_dfs["achievement_slug"] = [[y["slug"] for y in x] for x in summary_dfs.achievement_templates]
summary_dfs["achievement_description"] = [[y["description"] for y in x] for x in summary_dfs.achievement_templates]
summary_dfs["achievement_image_url"] = [[y["image_url"] for y in x] for x in summary_dfs.achievement_templates]
summary_dfs["achievement_id"] = [[y["id"] for y in x] for x in summary_dfs.achievement_templates]
summary_dfs["achievement_name"] = [[y["name"] for y in x] for x in summary_dfs.achievement_templates]
summary_dfs.drop("achievement_templates", axis=1, inplace=True)
summary_dfs["peloton_ride_class_type_ids"] = [x[0] for x in summary_dfs["peloton_ride_class_type_ids"]]
summary_dfs["peloton_ride_ride_type_ids"] = [x[0] for x in summary_dfs["peloton_ride_ride_type_ids"]]
summary_dfs["ride_captions"] = [x[0] if len(x) > 0 else '' for x in summary_dfs["ride_captions"]]
summary_dfs["ride_class_type_ids"] = [x[0] for x in summary_dfs["ride_class_type_ids"]]
summary_dfs["ride_ride_type_ids"] = [x[0] for x in summary_dfs["ride_ride_type_ids"]]
summary_dfs.to_csv("/home/rzwitch/Desktop/workout_summaries_parsed.csv", index = False)
workout_details = []
for wd in workoutids:
wd_str = f"""https://api.onepeloton.com/api/workout/{wd}/performance_graph?every_n=1"""
r = requests.get(wd_str, cookies = cookies)
workout_details.append(r.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.