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
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjaSource/1eb613da69df331273c9b44f2ec0101d to your computer and use it in GitHub Desktop.
Save cjaSource/1eb613da69df331273c9b44f2ec0101d to your computer and use it in GitHub Desktop.
Download all workouts from sports-tracker
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 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}"`);
// 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}";`);
// }
// }
function loopThroughItems() {
setInterval(downloadOne, 2000);
}
const items = document.querySelectorAll("ul.diary-list__workouts li a");
var iGlobal = 0;
document.body.innerHtml = '';
loopThroughItems(items);
@cjaSource
Copy link
Author

Works as of Aug 2023

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