Code to download all C2 logbook sessions
Posted: November 28th, 2023, 8:51 pm
Inspired by this github repository (https://github.com/arnold-c/garmin-backups) I wrote a piece of code to export all of the data from a C2 logbook to a set of json files. You need to get/create an API key in the Applications section when you edit your profile and plug it into the api_token variable, pip install requests if you don't already have it then you're off and running.
I wrote this code because there is no way to do bulk download of your logbook data that includes stroke data for every session that has it. In other words, bulk downloads only get you summary data. If you want detail data then you have to select every session and download it one by one. That sucks.
Once you have json output then you'll need to figure out what you want in that data and process/plot that. That's a totally different exercise and I'm hoping there are tools that already do that part.
I wrote this code because there is no way to do bulk download of your logbook data that includes stroke data for every session that has it. In other words, bulk downloads only get you summary data. If you want detail data then you have to select every session and download it one by one. That sucks.
Code: Select all
import requests
import json
api_root = 'https://log.concept2.com'
api_token = 'YOUR_API_TOKEN'
endpoint = f"{api_root}/api/users/me/results"
headers = {"Authorization": f"Bearer {api_token}"}
page = 1
next_page = endpoint
def getPage(nextPage):
global next_page
print(nextPage)
res = requests.get(nextPage, headers = headers)
outfile = 'page'+str(page)+'.json'
with open(outfile,'w') as f:
json.dump(res.json(),f,indent=4)
try:
next_page = res.json()["meta"]["pagination"]["links"]["next"]
except:
next_page = ''
while next_page != '':
getPage(next_page)
page += 1