bweiher / pelotonr Goto Github PK
View Code? Open in Web Editor NEWR package that interfaces with the Peloton API
License: Other
R package that interfaces with the Peloton API
License: Other
library(pelotonR)
library(tidyverse)
Sys.setenv("PELOTON_LOGIN" = "username")
Sys.setenv("PELOTON_PASSWORD" = "pw")
peloton_auth()
# ----------------------- get data about yourself
me <- get_my_info() # peloton_api("api/me")
user_id <- me$id
# ---------------- GET
pel_workouts <- get_all_workouts(user_id, num_workouts = me$total_workouts, joins = "ride,ride.instructor")
Error: Problem with `mutate()` input `live_stream_id`.
x character string is not in a standard unambiguous format
i Input `live_stream_id` is `(function (x, ...) ...`.
Getting this error when using joins = "ride,ride.instructor"
It appears there is a limit of 100 responses when querying workouts, which means you have to page through in batches of 100 to get all workouts (if you have more than 100). Right now page=0
is hardcoded into the function, but it seems like there should be a way to make it so you can specify the page. I am currently using this, where the only thing I'm modiying is the page_num
in the parameters and API call.
get_all_workouts_page <- function(userid = Sys.getenv("PELOTON_USERID"),
num_workouts = 20,
joins = "",
page_num = 0,
dictionary = list(
"numeric" = c(
"v2_total_video_buffering_seconds",
"v2_total_video_watch_time_seconds"
)
),
parse_dates = TRUE,
...) {
if (userid == "")
stop("Provide a userid or set an environmental variable `PELOTON_USERID`",
call. = FALSE)
if (length(joins) > 1 ||
!is.character(joins))
stop("Provide joins as a length one character vector", call. = FALSE)
# see if joins is provided, if so, append to request
if (joins != "")
joins <- glue::glue("joins={joins}")
workouts <-
peloton_api(
glue::glue(
"/api/user/{userid}/workouts?{joins}&limit={num_workouts}&page={page_num}"
),
...
)
n_workouts <- length(workouts$content$data)
# v2_total_video_buffering_seconds v2_total_video_watch_time_seconds
if (n_workouts > 0) {
workouts <-
purrr::map_df(
1:n_workouts,
~ parse_list_to_df(
workouts$content$data[[.]],
dictionary = dictionary,
parse_dates = parse_dates
)
)
# IF JOIN PARAM is specified, get data out for ride list and add it to that row
if (joins != "") {
rides <- purrr::map_df(1:n_workouts, function(x) {
parse_list_to_df(
stats::setNames(workouts$ride[[x]], paste0(
"ride_", names(workouts$ride[[x]])
)),
dictionary = dictionary,
parse_dates = parse_dates,
...
)
})
dplyr::left_join(
dplyr::mutate(workouts, rn = dplyr::row_number()),
dplyr::mutate(rides, rn = dplyr::row_number()),
by = "rn"
) %>%
dplyr::select(-.data$rn)
} else {
workouts
}
}
}
it would be cool to create a nice shiny dashboard that could:
update gathered data (maybe add to a local data store or DB ; incrementally find new data it needs)
create some plots based off data
show user progress
activity patterns, etc
I just discovered today I can download my peloton data. then through lucky googling I found this package. Was worried I'd have to do this myself... Thanks for your work here - you've made my day!
I'm getting an error when I try to retrieve my workouts:
library(pelotonR)
peloton_auth()
#> [1] "Logged in"
# get data about yourself
me <- get_my_info() # peloton_api("api/me")
user_id <- me$id
# get a list of your workouts
workouts <- get_all_workouts(user_id) # peloton_api("api/user_id/workouts")
#> Error: Can't combine `..1$v2_total_video_watch_time_seconds` <integer> and `..18$v2_total_video_watch_time_seconds` <character>.
if you run get_perfomance_graphs
(maybe get_all_workouts
, but would have to be smart) repeatedly you may have to fetch and process the same data many times.
its possible to cache which workouts already have fetched data, so it doesnt hit the API. older results could be stored in local files.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.