-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathride.gs
60 lines (56 loc) · 1.78 KB
/
ride.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function getRide(id){
var config=getConfigDetails();
var peloton=config.peloton;
var url=peloton.http_base +'/api/ride/'+id+"/details";
var json= UrlFetchApp.fetch(url,peloton.http_options).getContentText();
var data = JSON.parse(json);
console.log(data);
var ride=data.ride;
if(!ride.has_pedaling_metrics){
console.log("Ride does not have pedaling metrics. Cannot proceed");
return null;
}
var rideObj= {
id: ride.id,
aired: new Date(ride.original_air_time * 1000),
title: ride.title,
instructor:{
id:ride.instructor.id,
name: ride.instructor.name,
image_url: ride.instructor.image_url
},
workouts:ride.total_workouts,
image_url:ride.image_url,
duration:ride.duration,
difficulty_estimate:ride.difficulty_estimate,
overall_estimate: ride.overall_estimate,
}
console.log(rideObj);
return rideObj;
}
function testGetRide(){
var id="0f3c1aaa6b124b91a3691787f2d572ab";
var ride=getRide(id);
console.log("I got ride "+id);
}
function storeRide(ride, competition, workoutCount){
var event=eventStart("Store Ride", ride.id+","+competition+","+workoutCount);
var sheet=SpreadsheetApp.getActive().getSheetByName(RIDES_SHEET_NAME);
var row=[
new Date(), // Timestamp
ride.id, // ID
competition, // Competition
workoutCount, // Workout Count from this loadiong of the results
ride.title, // Title
ride.instructor.name, // Instructor
ride.instructor.id, // instructor ID
ride.aired, // Originally Aired
ride.workouts, // Total Workouts
ride.duration, // Duration
ride.image_url, // Ride IMAGE
ride.instructor.image_url //Instructor Image
];
sheet.getRange
sheet.getRange(sheet.getDataRange().getLastRow()+1, 1, 1, row.length).setValues([row]);
eventEnd(event);
}