Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2016 05:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save anonymous/9abc8d9c376bbc6aa853b477a50e8932 to your computer and use it in GitHub Desktop.
Save anonymous/9abc8d9c376bbc6aa853b477a50e8932 to your computer and use it in GitHub Desktop.
Download all workouts from sports-tracker
// 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.
//
// I've compiled the changes proposed in the comments in the script below.
// to use the script, login to your sports-tracker account
// change URL to http://www.sports-tracker.com/diary/workout-list
// open browser console (Cmd-Shift-I)
// paste the script, hit enter - it'll run and print something like this to the cosole:
// curl -o SportsTracker-<..id..>.gpx "http://www.sports-tracker.com/apiserver....."
// right-click on the colsole and save the contents to a file, call it download-all-workouts.sh
// open terminal, change to the directory where you saved the contents of the console
// edit the file - remove the javascript at the beginning of the file leaving only curl commands
// fix permissions:
// $>chmod +x download-all-workouts.sh
// run the script:
// $>./download-all-workouts.sh
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 = 'http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
var filename = 'SportsTracker-' + id + '.gpx';
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);
@vanessaforney
Copy link

Thank you, this was very useful!

@byobi
Copy link

byobi commented Jul 17, 2017

yes - thank you!

I converted your script to generate the PowerShell equivalent... just change line 33

from:
console.log('curl -o ' + filename + ' "' + url + '";sleep 2');
to:
console.log('Invoke-WebRequest -Uri ' + ' "' + url + '" -OutFile "' + filename + '"');

@safason
Copy link

safason commented Jul 18, 2017

Excellent job, thanks!

@dd121
Copy link

dd121 commented Sep 7, 2017

Thanks for the code, works like a charm!

@nenomart
Copy link

Hello
Sorry, I do not know where I put code on the page?
Thank you

@istvans
Copy link

istvans commented Nov 1, 2017

Awesome, thank you!

@devalls
Copy link

devalls commented Dec 14, 2017

Thanks!

@bANDYka
Copy link

bANDYka commented Dec 17, 2017

got to the point when I have the workouts in the console with byobi's change like, what should I do now? if

Invoke-WebRequest -Uri "http://www.sports-tracker.com/apiserver/v1/workout/exportGpx/51f015ace4b07b2c0b8f38ad?token=5k9r27le21f05q423t8okbip3m4d2klo" -OutFile "SportsTracker-51f015ace4b07b2c0b8f38ad.gpx"

I open a Windows powershell and copy paste the url's I am getting error messages
_VM4110:33 : The term 'VM4110:33' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:2 char:1

  • VM4110:33 Invoke-WebRequest -Uri "http://www.sports-tracker.com/apis ...
  •   + CategoryInfo          : ObjectNotFound: (VM4110:33:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException_
    

@alistairadamsqt
Copy link

You need to remove VM4110:33 from the command. This is information from the google console that is superfluous.

@bonzotronix
Copy link

Thanks very much for providing this script!

@gnouros
Copy link

gnouros commented Feb 21, 2018

Hi !

Great script! It saved my day from multiple manual downloads.

However, Sports Tracker changed the way to access the files. Now it uses https instead of raw http.

So, in order the script to work, you have to change line 31 by the following :

var url = 'https://www.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;

Hope that helps!

@rjvdboon
Copy link

rjvdboon commented Jul 4, 2018

I noticed that the token parsing doesn't work (for me), there is no trailing ;.
Another thing I found annoying was that I needed to click "Load More" multiple times (and it relies too much on html structure). There is a apiserver/v1/workouts/ api that can give you all workouts in JSON format.
I've applied both to my fork: https://gist.github.com/rjvdboon/54b9bbb8c56471fd864c00422b92a722

@gmananton
Copy link

gmananton commented Jan 4, 2019

Please change API url from http://www.sports-tracker.com/apiserver/ to https://sports-tracker.com/apiserver/
Otherwise all downloaded files are the same size and contain this:

<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>

@mmardegan
Copy link

Thank you!!! Excellent work ;-)

@dufoq3
Copy link

dufoq3 commented Feb 12, 2019

Great, many thanks!

@Bilan
Copy link

Bilan commented Nov 2, 2020

I fixed some bugs and added activity images downloading:
https://gist.github.com/Bilan/33770ecb8160ee1a79864bd3d37c0f03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment