Skip to content

Instantly share code, notes, and snippets.

@cjaSource
Forked from bilan/sports-tracker-download.js
Last active August 18, 2023 11:21
Show Gist options
  • Save cjaSource/1eb613da69df331273c9b44f2ec0101d to your computer and use it in GitHub Desktop.
Save cjaSource/1eb613da69df331273c9b44f2ec0101d to your computer and use it in GitHub Desktop.

Revisions

  1. cjaSource revised this gist Aug 18, 2023. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,14 @@ const token = document.cookie.substring(valueStartIndex, document.cookie.indexOf
    const activities = {0:"walk",1:"run",2:"ride",11:"hike",13:"alpineski",14:"rowing",15:"rowing"};

    function downloadOne(item) {
    var item = items[iGlobal];
    const href = item.href;
    const id = href.substr(href.lastIndexOf('/') + 1, 24);
    const url = 'https://api.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
    console.log(url);
    window.open(url);
    ++iGlobal;

    // const activityId = item.querySelector(".activity-icon").getAttribute('activity-icon');
    // const filename = `id--${id}--activity--${activities[activityId]}--title--${item.querySelector(".description").title.replace('/',',')}--file.gpx`;
    // console.log(`mkdir "${id}"`);
    @@ -28,14 +31,12 @@ function downloadOne(item) {
    // }
    // }

    function loopThroughItems(items) {
    for (let i = 0; i < items.length; i++) {
    // Sleep a bit
    await new Promise(r => setTimeout(r, 500));
    downloadOne(items[i]);
    }

    function loopThroughItems() {
    setInterval(downloadOne, 2000);
    }

    const items = document.querySelectorAll("ul.diary-list__workouts li a");
    var iGlobal = 0;
    document.body.innerHtml = '';
    loopThroughItems(items);
  2. cjaSource revised this gist Aug 18, 2023. 1 changed file with 20 additions and 45 deletions.
    65 changes: 20 additions & 45 deletions sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,3 @@
    // Bilan: My fork fixed some api changes, added images downloading and informative gpx file names. Works on 2020/11/02.
    //
    // You can then upload it to Strava using this oneliner:
    // find * -name '*.gpx' -print0 | while read -d $'\0' i; do ID=`echo $i | sed 's/.*id--//' | sed 's/--activity.*//'`; ACTIVITY=`echo $i | sed 's/.*--activity--//' | sed 's/--title.*//'`; NAME=`echo $i | sed 's/--file.gpx//' | sed 's/.*--title--//'`" ($ID/$ACTIVITY)"; echo "\n$NAME\n"; curl -X POST https://www.strava.com/api/v3/uploads -H "Authorization: Bearer ___TOKEN___" -F file=@"$i" -F data_type="gpx" -F description="SportsTracker import" -F name="$NAME" -F external_id="$i"; sleep 10;done
    //
    // Original desc:
    // 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

    const key = "sessionkey=";
    const valueStartIndex = document.cookie.indexOf(key) + key.length;
    const token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(';', valueStartIndex));
    @@ -36,27 +7,31 @@ function downloadOne(item) {
    const href = item.href;
    const id = href.substr(href.lastIndexOf('/') + 1, 24);
    const url = 'https://api.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
    const activityId = item.querySelector(".activity-icon").getAttribute('activity-icon');
    const filename = `id--${id}--activity--${activities[activityId]}--title--${item.querySelector(".description").title.replace('/',',')}--file.gpx`;
    console.log(`mkdir "${id}"`);
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    downloadImages(id);
    console.log(url);
    window.open(url);
    // const activityId = item.querySelector(".activity-icon").getAttribute('activity-icon');
    // const filename = `id--${id}--activity--${activities[activityId]}--title--${item.querySelector(".description").title.replace('/',',')}--file.gpx`;
    // console.log(`mkdir "${id}"`);
    // console.log(`curl -o "${id}/${filename}" "${url}";`);
    // downloadImages(id);
    }

    async function downloadImages(id) {
    const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    const imageApiResponse = await fetch(imagesUrl);
    const images = (await imageApiResponse.json()).payload;
    for (let i = 0; i < images.length; i++) {
    let image = images[i];
    let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    let url = `https://api.sports-tracker.com/apiserver/v1/image/scale/${image.key}.jpg?width=${image.width}&height=${image.height}`;
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    }
    }
    // async function downloadImages(id) {
    // const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    // const imageApiResponse = await fetch(imagesUrl);
    // const images = (await imageApiResponse.json()).payload;
    // for (let i = 0; i < images.length; i++) {
    // let image = images[i];
    // let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    // let url = `https://api.sports-tracker.com/apiserver/v1/image/scale/${image.key}.jpg?width=${image.width}&height=${image.height}`;
    // console.log(`curl -o "${id}/${filename}" "${url}";`);
    // }
    // }

    function loopThroughItems(items) {
    for (let i = 0; i < items.length; i++) {
    // Sleep a bit
    await new Promise(r => setTimeout(r, 500));
    downloadOne(items[i]);
    }
    }
  3. @bilan bilan revised this gist Nov 2, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ async function downloadImages(id) {
    const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    const imageApiResponse = await fetch(imagesUrl);
    const images = (await imageApiResponse.json()).payload;
    for (i = 0; i < images.length; i++) {
    for (let i = 0; i < images.length; i++) {
    let image = images[i];
    let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    let url = `https://api.sports-tracker.com/apiserver/v1/image/scale/${image.key}.jpg?width=${image.width}&height=${image.height}`;
  4. @bilan bilan revised this gist Nov 2, 2020. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@

    // run the script:
    // $>./download-all-workouts.sh

    const key = "sessionkey=";
    const valueStartIndex = document.cookie.indexOf(key) + key.length;
    const token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(';', valueStartIndex));
    @@ -37,20 +38,20 @@ function downloadOne(item) {
    const url = 'https://api.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
    const activityId = item.querySelector(".activity-icon").getAttribute('activity-icon');
    const filename = `id--${id}--activity--${activities[activityId]}--title--${item.querySelector(".description").title.replace('/',',')}--file.gpx`;
    console.log(`mkdir "${id}"`);
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    downloadImages(id);
    console.log(`mkdir "${id}"`);
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    downloadImages(id);
    }

    async function downloadImages(id) {
    const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    const imageApiResponse = await fetch(imagesUrl);
    const images = (await imageApiResponse.json()).payload;
    for (i = 0; i < images.length; i++) {
    let image = images[i];
    let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    let image = images[i];
    let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    let url = `https://api.sports-tracker.com/apiserver/v1/image/scale/${image.key}.jpg?width=${image.width}&height=${image.height}`;
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    }
    }

  5. @bilan bilan revised this gist Nov 2, 2020. 1 changed file with 35 additions and 19 deletions.
    54 changes: 35 additions & 19 deletions sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    // Bilan: My fork fixed some api changes, added images downloading and informative gpx file names. Works on 2020/11/02.
    //
    // You can then upload it to Strava using this oneliner:
    // find * -name '*.gpx' -print0 | while read -d $'\0' i; do ID=`echo $i | sed 's/.*id--//' | sed 's/--activity.*//'`; ACTIVITY=`echo $i | sed 's/.*--activity--//' | sed 's/--title.*//'`; NAME=`echo $i | sed 's/--file.gpx//' | sed 's/.*--title--//'`" ($ID/$ACTIVITY)"; echo "\n$NAME\n"; curl -X POST https://www.strava.com/api/v3/uploads -H "Authorization: Bearer ___TOKEN___" -F file=@"$i" -F data_type="gpx" -F description="SportsTracker import" -F name="$NAME" -F external_id="$i"; sleep 10;done
    //
    // Original desc:
    // 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
    @@ -20,30 +26,40 @@

    // 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));
    const key = "sessionkey=";
    const valueStartIndex = document.cookie.indexOf(key) + key.length;
    const token = document.cookie.substring(valueStartIndex, document.cookie.indexOf(';', valueStartIndex));
    const activities = {0:"walk",1:"run",2:"ride",11:"hike",13:"alpineski",14:"rowing",15:"rowing"};

    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');
    const href = item.href;
    const id = href.substr(href.lastIndexOf('/') + 1, 24);
    const url = 'https://api.sports-tracker.com/apiserver/v1/workout/exportGpx/' + id + '?token=' + token;
    const activityId = item.querySelector(".activity-icon").getAttribute('activity-icon');
    const filename = `id--${id}--activity--${activities[activityId]}--title--${item.querySelector(".description").title.replace('/',',')}--file.gpx`;
    console.log(`mkdir "${id}"`);
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    downloadImages(id);
    }

    function loopThroughItems(items)
    {
    var i = 0;
    for (i = 0; i < items.length; i++) {
    downloadOne(items[i]);

    async function downloadImages(id) {
    const imagesUrl = 'https://api.sports-tracker.com/apiserver/v1/images/workout/' + id + '?token=' + token;
    const imageApiResponse = await fetch(imagesUrl);
    const images = (await imageApiResponse.json()).payload;
    for (i = 0; i < images.length; i++) {
    let image = images[i];
    let filename = `${id}-${image.key}-${image.location.x}-${image.location.y}-${image.timestamp}.jpg`;
    let url = `https://api.sports-tracker.com/apiserver/v1/image/scale/${image.key}.jpg?width=${image.width}&height=${image.height}`;
    console.log(`curl -o "${id}/${filename}" "${url}";`);
    }
    }

    function loopThroughItems(items) {
    for (let i = 0; i < items.length; i++) {
    downloadOne(items[i]);
    }
    }

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

    loopThroughItems(items);
  6. @invalid-email-address Anonymous created this gist Dec 9, 2016.
    49 changes: 49 additions & 0 deletions sports-tracker-download.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // 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);