-
Notifications
You must be signed in to change notification settings - Fork 16
/
api_debug.py
executable file
·53 lines (41 loc) · 1.51 KB
/
api_debug.py
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
"""This script will give you a giant dictionary that can be used."""
#!/usr/bin/python3
import getopt
import json
import sys
from typing import Any
import pylotoncycle
def main(argv: Any) -> None:
"""Output raw data from Peloton API to console."""
username = ""
password = ""
try:
opts, _ = getopt.getopt(argv, "hu:p:", ["user=", "pass="])
except getopt.GetoptError:
print("api_debug.py -u <user> -p <pass>")
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
print("api_debug.py -u <user> -p <pass>")
sys.exit()
elif opt in ("-u", "--user"):
username = arg
elif opt in ("-p", "--pass"):
password = arg
try:
conn = pylotoncycle.PylotonCycle(username, password)
except pylotoncycle.pylotoncycle.PelotonLoginException:
print("Login or Password incorrect")
else:
workouts = conn.GetRecentWorkouts(5)
latest_workout = workouts[0]
user_profile = conn.GetMe()
latest_workout_metrics = conn.GetWorkoutMetricsById(workouts[0]["id"])
print("\n==================[ USER PROFILE ]==================[\n")
print(json.dumps(user_profile))
print("\n==================[ LATEST WORKOUT OVERVIEW ]==================[\n")
print(json.dumps(latest_workout))
print("\n==================[ LATEST WORKOUT METRICS ]==================[\n")
print(json.dumps(latest_workout_metrics))
if __name__ == "__main__":
main(sys.argv[1:])