Python scripts for transferring tours from Komoot to Strava activities.
The whole script is divided into four parts:
komoot-get-tours.pykomoot-get-gpx.pykomoot-to-strava-mapper.pystrava-upload-activites.py
plus config.py for configuration and utils.py for common functions.
komoot-get-tours.py and komoot-get-gpx.py download activities data and GPX files from your Komoot account. This script is a little bit tricky because it uses Komoot API endpoint without any authorization. Thus, it can download data only from public activities and only from public accounts. Also the "Privacy zones" must be disabled for the time of script run, otherwise, the downloaded GPX files will be truncated by these zones. Komoot tours data by default is saved to ./data/komoot-tours.json file and GPX files to ./data/{TOUR_ID}.gpx.
komoot-to-strava-mapper.py maps data saved in ./data/komoot-tours.json to a model required for uploading activity to Strava. Output is saved by default in ./data/strava-activities.json
strava-upload-activies.py - upload activities to your Strava account. This script uses authorization, also in a kind of tricky way. To use it, you have to register own Strava API application and obtain client id, client secret, authorization code and access token with activity:write scope.
I wrote the script for my personal, one-time use, therefore it is generally quite janky, however - for me - it did the job (though it turned out that I wanted to use it again after some time, so I rewrote most of the code - still janky).
Scripts were developed with python3.
- Make sure that your profile is public, all your tours all public and your privacy zones are disabled. You can easily switch them back after the export.
- Go to the
Settings > Account > User IDand copy your user ID. - Open the
config.pyfile and paste your user ID to the variable thekomoot_user_idas a number:komoot_user_id = 012345679
- Go to the
./srcdirectory and run thekomoot-get-tours.pyfrom the terminal:$ cd src $ python3 komoot-get-tours.py - Wait until the script finishes.
- Run the
komoot-get-gpx.pyfrom the terminal:$ cd src $ python3 komoot-get-gpx.py - Wait until the script finishes.
- You can now switch back your privacy settings to more private and bring back 'Privacy zones'.
- Go to the
./srcdirectory and runkomoot-to-strava-mapper.pyfrom the terminal:$ cd src $ python3 komoot-to-strava-mapper.py - Wait until the script finishes.
-
Using this instruction get your
authorization code:- In your browser go to the given address. Change the
[CLIENT_ID]to your client ID: https://www.strava.com/oauth/authorize?client_id=[CLIENT_ID]&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=activity:write - Authorize with your Strava account and wait for redirect (it will redirect you to the page, that doesn't exist - it's ok).
- After the redirect, copy the
code(which is yourauthorization code) from the address: http://localhost/exchange_token?state=&code=[HERE_IS_THE_CODE_TO_COPY]&scope=read,activity:write
- In your browser go to the given address. Change the
-
Now paste the
client id,client secret(both from your application page) and theauthorization code(copied from the previous step) in theconfig.pyfile:""" strava_client_id = "<client id>" strava_client_secret = "<client secret>" strava_authorization_code = "<authorization code>" strava_access_token = "" # see the note below -
Go to the
./srcdirectory and runstrava-upload-activities.pyfrom the terminal:$ cd src $ python3 strava-upload-activities.py -
Wait until the script finishes.
Note: after the first strava-upload-activities.py script run you will receive your access token and your authorization code becomes invalid. The access token has a long expiration time. So to avoid the need for authorization of every script run, you can copy your access token (it will be printed in the console on the first run) and paste it to conifg.py file under the strava_access_token variable.
- Strava has API limits. Every uploaded activity is equal to one call, so if you want to upload a lot of activities, you might need to manually split them into smaller chunks and spread uploading in time. The easiest way to do it would be to manually edit the
strava-activities.jsonfile - just cut out a chunk of activities, and back it up in another file. Upload the current chunk and then replace the data. - In case of missing files, already existing files, unexpected errors, bad API calls, etc. the scripts will most likely just stop working.
- You might need to manually create an empty
datafolder before running scripts. - You can adjust the config in the
config.pyfile, including the sport types map: