Skip to content

Instantly share code, notes, and snippets.

@quiver
Last active January 8, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quiver/1dc414da3f32f7a6b68d0723a912c956 to your computer and use it in GitHub Desktop.
Save quiver/1dc414da3f32f7a6b68d0723a912c956 to your computer and use it in GitHub Desktop.
Python Script to get data from COROS Training Hub
'''
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":"foo@example.com","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