Skip to content

al-codaio/peloton-coda-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 

Repository files navigation

Coda API 1.0.0

Sync your Peloton workouts to Coda

This script is no longer updated. The most updated script is now handled by the Coda Peloton Pack.

I have created a Coda template you can copy which contains the tables setup for syncing your own Peloton data. I try to make updates to the charts and dashboards in the template so check the template for new functionality.

May 23rd, 2022 Update

  • You can add which type of workouts you want to sync in Synced Workouts by changing the "workout type" in the sync table settings. This limits the number of workouts returned to the type you care about.
  • The types should be separated by commas. Options are cycling, strength, yoga, stretching, running, walking, cardio, meditation, bike_bootcamp, outdoor, and bootcamp (tread).

May 14th, 2022 Update

  • Added average output/minute to the Browse Instructors page showing your output/min for all the cycling classes you've taken with a given instructor
  • The Friends' Cycling Leaderboard automatically defaults to all your friends selected when you copy the template
  • Fixed the Monthly: Average Output, Cadence, Resistance, Speed chart on the Cycling page to show avg. Cadence, Resistance, and Speed correctly

🎉 Kudos to Makon for reporting these issues!

May 13th, 2022 Update

  • Fixed a bug with walking and running workouts which would break the Pack
  • For walking and running workouts, the pace for your walk/run shows up in the Avg Cadence column
  • Elevation will show up in the Total Output column

🎉 Kudos to Dena for reporting this bug!

May 11th, 2022 Update

  • Added a Non-Cycling page to show stats around your non-cycling workouts
  • View 10 most recent non-cycling workouts, total minutes by month, and avg. start time

🎉 Kudos to Mat for the suggestion!

May 9th, 2022 Update

tl;dr: I'll no longer be updating the Google Apps Script. I'll be updating the Peloton Pack in Coda with new features going forward. The template uses the Peloton Pack and the Google Apps Script won't work with this template anymore.

Here's a video tutorial on how the Peloton Pack works in Coda peloton pack in coda

December 11th, 2021 Update

  • Fixed issue with Google Apps Script only where only 100 workouts were being returned from API

March 2nd, 2021 Update

  • Added friends' latest cycling workouts to Google Apps Script
  • New table Friend Workouts contains latest 10 cycling workouts from people you follow
  • Friends' Cycling Leaderboard shows how your stats compare with those of your friends

February 28th, 2021 Update

  • Added a monthly view of your cycling workouts to the Cycling dashboard (see Monthly Cycling Stats)
  • Added monthly charts to the Cycling dashboard as well
  • Added pie chart of all workouts by instructors to Cycling (see Workouts by instructor)
  • Some tidying up: collapsed some charts and views in Cycling
  • Fixed Google Apps Script to account for a variety of other workouts

What these scripts do

There are two scripts in this repo you can run to sync your Peloton workout data to a Coda doc. One script is meant to be run in Google Apps Scripts and the other is a Python script you can run as a traditional cron job:

  1. peloton_coda_gas.js - For Google Apps Script (gist)
  2. peloton_coda_python.py - Python script to run locally or in the cloud as a cron job (gist)

Setup for Google Apps Script

Starting in line 10 to line 13 of the peloton_coda_gas.js script, you'll need to enter in some of your own data to make the script work.

CodaAPI.authenticate('YOUR_CODA_API_KEY')
CODA_DOC_ID = 'YOUR_CODA_DOC_ID'
PELOTON_USERNAME = 'YOUR_PELOTON_USERNAME'
PELOTON_PASSWORD = 'YOUR_PELOTON_PASSWORD'

Step-by-step:

  1. Go to script.google.com and create a new project and give your project a name.
  2. Click on Libraries and enter the following string into the "Script ID" field: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl. Note: If you are using the legacy Google Apps Scripted editor, go to Libraries then Resources in the toolbar.
  3. Click Lookup and then select version 9 of library to use (as of January 2021, version 9 - Coda API v1.0.0 is the latest). Don't touch the other settings. Click Add.
  4. Copy and paste the entire script into your Google Apps Script editor (by default, the script name is "Code.gs")
  5. Go to your Coda account settings, scroll down until you see "API SETTINGS" and click Generate API Token. Copy and paste that API token into the value for YOUR_CODA_API_KEY in the script. Note: do not delete the single apostrophes around YOUR_CODA_API_KEY.
  6. Make a copy of this template if you haven't already.
  7. In the Coda doc you created, go to the "All Workouts" page and delete all the dummy data by clicking the Clear example data button.
  8. Get the the doc ID from your Coda doc by copying and pasting all the characters after the _d in the URL of your Coda doc (should be about 10 characters). You can also use the Doc ID Extractor tool in the Coda API docs. Copy and paste your doc ID into YOUR_CODA_DOC_ID in the script.
  9. Fill in your Peloton username and password in YOUR_PELOTON_USERNAME and YOUR_PELOTON_PASSWORD (remember to keep the single quotes around both values).
  10. Click the dropdown menu next to the Debug button in the toolbar and select the runPelotonSync option.
  11. Click the Run ▶️ button and this sync all your Peloton workout data to the Workouts table in your Coda doc. Google may ask you to approve some permissions. You will get a message saying "Google hasn't verified this app." Click on Advanced and click on Go to (script name) to proceed).
  12. Get the script to run daily by clicking on the clock 🕒 icon on the left sidebar and set up a time-driven trigger.
  13. Click create a new trigger, make sure runPelotonSync is set as the function to run, "Select event source" should be Time-driven, and the type to "Hour timer."

Setup for Python script

You have more flexibility with where and how you run the Python script. The steps below is one method for setting up a serverless function to run on Google Cloud Platform.

Step-by-step:

  1. Set up a Google Cloud Platform project and enable the Cloud Functions API and Cloud Scheduler API.
  2. Create a Google Cloud Function and check "Allow unauthenticated invocations":
  3. In the source code, select "Python 3.7" as the "Runtime" and edit the "Entry point" to a name like runPelotonSync.
  4. Copy and paste the whole Python script into main.py.
  5. Above line 19, "wrap" the whole script within a function like pelotonData (you may have to indent all the code below the function declaration):
def pelotonData(request):
  # Current workout IDs
  table_name = 'Workouts'
  headers = {'Authorization': 'Bearer ' + api_key}
  current_workout_ids = []
  ...
  1. Click Deploy at the bottom of the screen and wait until you see the green checkmark in the Google Cloud Functions list.
  2. Click into your new function and click Trigger to get the URL for triggering the script to run.
  3. Set up a Google Cloud Scheduler job to run the script every day, week, etc. You would set the "Target" in the Cloud Scheduler job with the URL you got from your Google Cloud Function.

Notes and caveats

  • The Peloton API used in these scripts are unofficial, so there is no documentation from Peloton regarding the use of their API. They may change the API at any point in time.
  • Don't be too aggressive with how often you run either script. Peloton may start rate-limiting you.
  • Don't share your Coda API key and Peloton login details
  • Props to @geudrik and his Peloton Client Library. Use his library if you want to develop a custom application with your Peloton data.

Old Video Tutorial

sync peloton data to coda

About

Sync workout stats from Peloton to a Coda doc

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published