Data Migration from sports-tracker.com to strava.com

A few years ago, I used the Sports-Tracker.com app for activity logging. After switching to Strava, I wanted to move my activity data to the new platform. Sports-Tracker allows exporting of activities, but only one-by-one. This is rather tedious with a few hundred activities.

Then I came across a small script that will create batch download commands for each activity when run in Chrome. The original script can be found here, but I had to do a few slight modifications to make it work again.

// based entirely on this blog post:
// http://druss.co/2016/04/export-all-workouts-from-sports-tracker/
// unfortunately the original script no longer works, moslty because jQuery is 
// no longer available on sports-tracker pages.
// 

var key = "sessionkey=";
var valueStartIndex = document.cookie.indexOf(key) + key.length;
var token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(';', valueStartIndex));
function downloadOne(item) {
    var href = item.href;
    var id = href.substr(href.lastIndexOf('/') + 1, 24);
    var url = 'https://www.sports-tracker.com/apiserver/v1/workout/exportFit/' + id + '?token=' + token;
    var filename = 'SportsTracker-' + id + '.fit';
    console.log('curl -o ' + filename + ' "' + url + '";sleep 2');
} 
function loopThroughItems(items)
{
    var i = 0;
    for (i = 0; i < items.length; i++) {
        downloadOne(items[i]);
}
var items = document.querySelectorAll("ul.diary-list__workouts li a");
document.body.innerHtml = '';
loopThroughItems(items); 

To run the script, you have to do the following:
1) Login to your sports-tracker account using Google Chrome
2) Change URL to https://www.sports-tracker.com/diary/workout-list
3) Open browser console (Ctrl-Shift-I)
4) Paste the script, hit enter – it’ll run and print something like this to the cosole:
curl -o SportsTracker-<..id..>.fit „https://www.sports-tracker.com/apiserver…..“
5) Right-click on the colsole and save the contents to a file – call it something like „download-all-workouts.sh“
6) Edit the file: remove the javascript at the beginning of the file leaving only curl commands
6) Open (Linux bash) terminal (MinGW would be an option if you are using Windows)
7) Change to the directory where you saved the contents of the console
8) Fix permissions using chmod +x download-all-workouts.sh
9) Run the script: ./download-all-workouts.sh

Alternatively, you could download GPX files instead of FIT files. Just replace all occurences of fit with gpx in the JavaScript.

Some files will be downloaded with zero length. Just put the corresponding curl statements in another script and run it again until all files have been downloaded correctly.

Data migration from Sport Tracks (Windows application) to Strava

The Sport Tracks windows application allows exporting all activity data in GPX format. You can select the activities to be exported in activity view and then select export and GPX from the menu bar on the left.

Unfortunately, all activties will be exported into a single GPX file. Strava on the other hand needs a single activity per file to be able to import GPX data.

For this reason, I’ve written a small bash script that can split the single export file from Sport Tracks into many files containing just one activity for importing in Strava.

Here is the script:

#!/bin/bash
input="export-from-sport-tracks.gpx"
head -3 "$input" >/tmp/header
mkdir -p files 2>/dev/null
cd files
rm -f xx[0-9][0-9[0-9][0-9] [0-9].gpx
csplit -n 4 "../$input" '/^ /' '{}'
for f in $(echo xx*)
do
     [[ $f == xx0000 ]] && continue
     newf="${f:2:4}.gpx"
     echo "Creating $newf from $f"
     cp xx0000 $newf
     cat $f >>$newf
     echo "" >>$newf
     rm -f $f
done

In order to run it, you need to replace the value of the input variable by the filename of your Sport Tracks. The script runs under any flavour of Linux (I used Ubuntu 16.04), probably (I didn’t test it) under Windows Subsystem for Linux as well.

The result will be a directory called „files“ containing a separate GPX file for each activity contained in the Sport Tracks export that can be imported to Strava (up to 25 files at a time) through their web interface right away.