-
-
Save KonstantinosSykas/dfe4c5e392e299ab9341d6e16299454f to your computer and use it in GitHub Desktop.
Download all workouts from sports-tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
// KonstantinosSykas 2020-04-21: | |
// (1) Server name for exports has changed from 'www.sports-tracker.com' to | |
// 'api.sports-tracker.com'. | |
// (2) Updated code to include activity type and date in the filename. | |
// (3) To export in .fit format, in the URL path replace the 'exportGpx' with | |
// 'exportFit' (without quotes) and replace the filename suffix '.gpx' | |
// with '.fit' accordingly. | |
// (4) All of the above tested successfully on Win10/PowerShell with Chrome. | |
var key = "sessionkey="; | |
var valueStartIndex = document.cookie.indexOf(key) + key.length; | |
const token_len = 32; | |
var token = document.cookie.substr(valueStartIndex, token_len); | |
function downloadOne(item) { | |
// Get activity type | |
var activities = ["Walking", "Running", "Cycling", "CrossCountrySkiing", "Other1", "Other2", "Other3", "Other4", "Other5", "Other6", "MountainBiking", "Hiking", "RollerSkating", "AlpineSkiing", "Paddling", "Rowing", "Golf", "Indoor", "Parkour", "BallGames", "OutdoorGym", "PoolSwimming", "TrailRunning", "Gym", "NordicWalking", "HorsebackRiding", "Motorsports", "Skateboarding", "WaterSports", "Climbing", "Snowboarding", "SkiTouring", "FitnessClass", "Soccer", "Tennis", "Basketball", "Badminton", "Baseball", "Volleyball", "AmericanFootball", "TableTennis", "RacquetBall", "Squash", "Floorball", "Handball", "Softball", "Bowling", "Cricket", "Rugby", "IceSkating", "IceHockey", "Yoga", "IndoorCycling", "Treadmill", "Crossfit", "Crosstrainer", "RollerSkiing", "IndoorRowing", "Stretching", "TrackAndField", "Orienteering", "StandupPaddling", "MartialArts", "Kettlebell", "Dancing", "SnowShoeing", "Frisbee", "Futsal", "Multisport", "Aerobics", "Trekking", "Sailing", "Kayaking", "CircuitTraining", "Triathlon", "Undefined1", "Cheerleading", "Boxing", "ScubaDiving", "FreeDiving", "AdventureRacing", "Gymnastics", "Canoeing", "Mountaineering", "TelemarkSkiing", "OpenwaterSwimming", "Windsurfing", "KitesurfingKiting", "Paragliding", "Undefined2", "Snorkeling", "Surfing", "Swimrun", "Duathlon", "Aquathlon", "ObstacleRacing", "Fishing", "Hunting"]; | |
var activity_type_id = item.children[0].attributes[1].value; | |
var activity_type = activities[activity_type_id]; | |
// Get activity date and convert it to YYYYMMDD format | |
var activity_summary = item.innerText.substr(item.innerText.indexOf('\n') + 1); | |
var activity_date= activity_summary.substr(0, activity_summary.indexOf('\n')); | |
var activity_year = activity_date.substr(activity_date.lastIndexOf(',') + 2, 4); | |
var activity_month = '00'; | |
switch(activity_date.substr(0, 3)) { | |
case 'Jan': | |
activity_month = '01'; | |
break; | |
case 'Feb': | |
activity_month = '02'; | |
break; | |
case 'Mar': | |
activity_month = '03'; | |
break; | |
case 'Apr': | |
activity_month = '04'; | |
break; | |
case 'May': | |
activity_month = '05'; | |
break; | |
case 'Jun': | |
activity_month = '06'; | |
break; | |
case 'Jul': | |
activity_month = '07'; | |
break; | |
case 'Aug': | |
activity_month = '08'; | |
break; | |
case 'Sep': | |
activity_month = '09'; | |
break; | |
case 'Oct': | |
activity_month = '10'; | |
break; | |
case 'Nov': | |
activity_month = '11'; | |
break; | |
case 'Dec': | |
activity_month = '12'; | |
break; | |
} | |
var activity_day = activity_date.substr(4, 2); | |
var twodigits = activity_day.lastIndexOf(',') - 1; | |
if (!twodigits) { | |
activity_day = '0' + activity_day[0]; | |
} | |
activity_date = activity_year + activity_month + activity_day; | |
var href = item.href; | |
var id = href.substr(href.lastIndexOf('/') + 1, 24); | |
var url = 'http://api.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token; | |
var filename = 'SportsTracker-' + activity_type + '-' + activity_date + '-' + 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); | |
I'm sorry, but it was my fault. I used the command line instead of powershell.
@bobika99 excellent news! Have a great day! 🥳
Worked like a charm with Chrome under Win11 Pro 22H2! Thank you very much! Now that Sports Tracker has gone Premium on all of their usefull features its time finally export all my workouts and move on. 😄
EDIT: With 450+ workouts, I copy-pasted 100 lines directly into the powershell prompt, executed them, and repeated the process until all workouts were downloaded.
@DeR-RoN it's good that this still works. 💪
if you're getting 307 redirects, add -L to your commands. Example:
curl -L -o SportsTracker-Walking-.gpx "http://api.sports-tracker.com/apiserver/v1/workout/exportGpx/?token=";sleep 2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @bobika99,
I thought a bit more on that 403 error and a scenario came up where your case could have something to do with exceeded quota while hitting the sports-tracker api server or service.
What you could do, if that's the case, is to avoid exporting all your workouts at once. Split them in smaller groups and execute them one group at a time (or execute each group during different hours in a day, or even next day; I don't know how the quota could be configured by the sports-tracker web admin).
I tried to simulate the case exporting a larger group of workouts. There was no problem exporting 364 of them (sorry, I don't have more to test). I wonder how many workouts you are trying to export or if you have fiddled a bit with the
sleep
command of the script.Drop a note to share the outcome of your attempts.