Last active
February 6, 2025 16:13
-
-
Save quiver/1dc414da3f32f7a6b68d0723a912c956 to your computer and use it in GitHub Desktop.
Python Script to get data from COROS Training Hub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Python PoC to interact with COROS Training Hub. | |
URL : https://training.coros.com/ | |
This script retrieves COROS's activity list for 2022/12. | |
$ python3 coros_activity_list.py | |
date,name,sportType,totalTime,distance,calorie,trainingLoad | |
20221230,Foo Run,100,9538,14651.11,1266085,117 | |
20221218,Bar,100,14696,24009.9,2135983,264 | |
''' | |
import csv | |
import json | |
import sys | |
import requests | |
# get access token | |
headers = { | |
"content-type": "application/json", | |
} | |
payload = '{"account":"[email protected]","accountType":2,"pwd":"YOUR_HASHED_PASSWORD"}' # FIXME | |
URL_AUTH = "https://teamapi.coros.com/account/login" | |
res_auth = json.loads(requests.post(URL_AUTH, headers=headers, data=payload).text) | |
token = res_auth["data"]["accessToken"] | |
# get data | |
headers = { | |
"accesstoken": token, | |
"content-type": "application/json", | |
} | |
## data range : 20221201 to 20221231 | |
URL_DATA = "https://teamapi.coros.com/activity/query?size=50&pageNumber=1&startDay=20221201&endDay=20221231&modeList=" | |
res_data = json.loads(requests.get(URL_DATA, headers=headers).text) | |
# process data | |
header = [ | |
"date", | |
"name", | |
"sportType", | |
"totalTime", | |
"distance", | |
"calorie", | |
"trainingLoad", | |
] | |
cw = csv.DictWriter(sys.stdout, header, extrasaction="ignore") | |
cw.writeheader() | |
cw.writerows(res_data["data"]["dataList"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment