Export all workouts from Sports Tracker

By | April 3, 2016

Advertisement from Google

sports tracker export all workouts in gpx formatAlmost all sport tracking sites do not have “Export all” functionality. They want you to stay with them as long as possible. The same with Sports Tracker. There is no such functionality on their website, you can export workouts only one by one (which is annoying).

But with a bit of JS magic, we can download all workouts in GPX format.

  1. Login at http://www.sports-tracker.com/
  2. Go to http://www.sports-tracker.com/diary/workout-list
  3. Click “Show more” button at the end of the page until you have all workouts loaded.
  4. Go to developer console (press Ctrl + Shift + I in Google Chrome)
  5. Insert following JS and press Enter:

Advertisement from Google

var items = $("ul.workouts li a");

var key = "sessionkey=";
var valueStartIndex = document.cookie.indexOf(key) + key.length;
var token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(';', valueStartIndex));

$('body').html('');

$.each(items,function(i, value)
{
    var href = $(value).attr("href");
    var id = href.substr(href.lastIndexOf('/') + 1, 24);
    var url = 'http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
    var filename = 'SportsTracker-' + id + '.gpx';
    $.ajax({
        url: url,
        success: function(data, textStatus, jqXHR)
        {
            if(textStatus == 'success')
            {
                $('<a/>', {
                    'href' : 'data:text/plain;charset=utf-8,' + encodeURIComponent(jqXHR.responseText),
                    'download' : filename,
                    'id' : id
                }).html(filename)
                .before(i + '. Downloaded: ')
                .after('<br/>')
                .prependTo('body');

                $('#' + id)[0].click();
            }
            else
            {
                console.log(textStatus);
            }
        },
        dataType: 'xml'
    });
});

All gpx files will be in Download folder.

20 thoughts on “Export all workouts from Sports Tracker

  1. Joao

    Thank you very much for this solution!!

    I think sports tracker avoids creating an option for bulk exports to prevent people from moving to different platforms.

    Again, great solution!

    Reply
  2. Maxim

    Thanks! Great solution! I used another one, but it doesn’t get description.

    Reply
  3. Ondrej

    100% does not work 🙁
    I’ve got 272 workout and exports always more PCs only 208 🙁

    Reply
  4. MichalJ

    Since the script has no timeout, it often skips files on a network error basis. I recommend running it in batches of half-year of data (you can filter it in the ST interface). But overall it works like a charm. I exported about 200 workouts btw.

    The pain now is to get them into Strava where the upload limit is 25 files per upload 🙁

    Reply
  5. Dennis

    var items = $(“ul.workouts li a”); was not working for me, but var items = $(“ul.diary-list__workouts li a”); worked!
    Thanx

    Reply
  6. Philipp

    Worked like a charm, using Dennis’ variation of the code:
    var items = $(“ul.workouts li a”); was not working for me, but var items = $(“ul.diary-list__workouts li a”); worked!

    Thanks a lot!

    Reply
  7. Boris

    Its not working for me
    Tried with var items = $(“ul.workouts li a”); and with var items = $(“ul.diary-list__workouts li a”);

    Can someone help me?

    Reply
    1. Garry

      I think I have it now but when I insert the JS I am just left with the black back ground image from sport trackers page.

      Reply
  8. tedus

    As i don’t know programming at all:
    Code should be inserted into the “Console” tab of chrome developer (console) right? )+enter.

    There both solutions – the one from druss – and the one from dennis – that goes:

    var items = $(“ul.workouts li a”);
    was not working for me, but
    var items = $(“ul.diary-list__workouts li a”);
    worked!

    x
    var items = $(“ul.diary-list__workouts li a”);

    var key = “sessionkey=”;
    var valueStartIndex = document.cookie.indexOf(key) + key.length;
    var token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(‘;’, valueStartIndex));

    $(‘body’).html(”);

    $.each(items,function(i, value)
    {
    var href = $(value).attr(“href”);
    var id = href.substr(href.lastIndexOf(‘/’) + 1, 24);
    var url = ‘http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/’ + id + ‘?token=’ + token;
    var filename = ‘SportsTracker-‘ + id + ‘.gpx’;
    $.ajax({
    url: url,
    success: function(data, textStatus, jqXHR)
    {
    if(textStatus == ‘success’)
    {
    $(‘‘, {
    ‘href’ : ‘data:text/plain;charset=utf-8,’ + encodeURIComponent(jqXHR.responseText),
    ‘download’ : filename,
    ‘id’ : id
    }).html(filename)
    .before(i + ‘. Downloaded: ‘)
    .after(”)
    .prependTo(‘body’);

    $(‘#’ + id)[0].click();
    }
    else
    {
    console.log(textStatus);
    }
    },
    dataType: ‘xml’
    });
    });

    do not work for me.
    Druss solution leads to:
    Uncaught TypeError: $(…).html is not a function VM1415:7 at :7:11

    the one from Dennis leads to:
    Uncaught SyntaxError: Invalid or unexpected token VM1417:1

    Would be gread if anyone could give a hint as I don’t know anything about java (tried to search for missing ( or something like that though.

    Any idea??

    Reply
  9. tedus

    sorry – made a copy+paste error: the script by dennis i used is:

    var items = $(“ul.diary-list__workouts li a”);

    var key = “sessionkey=”;
    var valueStartIndex = document.cookie.indexOf(key) + key.length;
    var token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(‘;’, valueStartIndex));

    $(‘body’).html(”);

    $.each(items,function(i, value)
    {
    var href = $(value).attr(“href”);
    var id = href.substr(href.lastIndexOf(‘/’) + 1, 24);
    var url = ‘http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/’ + id + ‘?token=’ + token;
    var filename = ‘SportsTracker-‘ + id + ‘.gpx’;
    $.ajax({
    url: url,
    success: function(data, textStatus, jqXHR)
    {
    if(textStatus == ‘success’)
    {
    $(‘‘, {
    ‘href’ : ‘data:text/plain;charset=utf-8,’ + encodeURIComponent(jqXHR.responseText),
    ‘download’ : filename,
    ‘id’ : id
    }).html(filename)
    .before(i + ‘. Downloaded: ‘)
    .after(”)
    .prependTo(‘body’);

    $(‘#’ + id)[0].click();
    }
    else
    {
    console.log(textStatus);
    }
    },
    dataType: ‘xml’
    });
    });

    Reply
  10. Ernst

    hi tedus, same problem here. Different errors, so no export possible yet… Someone?

    Reply
  11. Sergi

    It’s possibble to download making a few changes at script.
    Change delay to configure timeout.
    Web was developped with angular and jQuery is not accesible from console, changed jquery references to javascript.

    var key = “sessionkey=”;
    var valueStartIndex = document.cookie.indexOf(key) + key.length;
    var token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(‘;’, valueStartIndex));
    var delay = 2000;

    var loopThroughItems = function (items) {
    var i = 0;
    function printEntry() {
    var href = items[i].getAttribute(“href”);
    var id = href.substr(href.lastIndexOf(‘/’) + 1, 24);
    var url = ‘http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/’ + id + ‘?token=’ + token;
    console.log(‘Remaining: ‘ + (items.length – i) + ‘ url: ‘ + url);
    document.location = url;
    i++; // Increment the position
    if (i < items.length) { // If there are more chars, schedule another
    setTimeout(printEntry, delay);
    }
    }
    printEntry(); // Print the first entry/char
    }

    var items = document.querySelectorAll("ul.diary-list__workouts li a");
    loopThroughItems(items);

    Reply
  12. MMe

    I managed to download my workouts with Chrome with the aid of the following extra steps:

    1. Change browser download settings such that browser is not asking location for each individual file (I think that downloading to ‘…/Downloads’ without asking anything is the default, but I had changed that to ask every time where to save the file. That made the script to fail.)
    2. Copy-paste jQuery to the console; before pressing enter, copy-paste the download script to console
    3. At the first line of script change ‘ul.workouts’ to ‘ul.diary-list__workouts’ and now press enter

    502 out of my 518 workouts got downloaded. The remaining 16 probably failed because of some network timeouts.
    Does anyone know if it’s possible to modify the script so that the names of the files are more meaningful? I’d like the name to be ‘Lat’+’Long’+’Activity_type’+’date’.gpx

    Reply
    1. shane

      vstr – thanks very much, had problems with original script as per other replies however your script worked perfectly.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *