Code to download all C2 logbook sessions

Topics relating to online racing and training with 3rd party software.
Post Reply
Posts: 49
Joined: September 19th, 2011, 10:33 am

Code to download all C2 logbook sessions

Post by slnm » November 28th, 2023, 8:51 pm

Inspired by this github repository ( 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.

Code: Select all

import requests
import json

api_root = ''
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
    res = requests.get(nextPage, headers = headers)
    outfile = 'page'+str(page)+'.json'
    with open(outfile,'w') as f:
        next_page = res.json()["meta"]["pagination"]["links"]["next"]
        next_page = ''
while next_page != '':
    page += 1
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.

Post Reply