Skip to content

Instantly share code, notes, and snippets.

@scompt
Last active October 19, 2020 15:43
Show Gist options
  • Save scompt/ade464f320db3220bdc8f940af875a6a to your computer and use it in GitHub Desktop.
Save scompt/ade464f320db3220bdc8f940af875a6a to your computer and use it in GitHub Desktop.
A script to download workouts and exercise alternatives. Prerequisites are GNU Parallel, cURL, and jq.
#!/bin/bash
USERNAME=d@t.com
PASSWORD=r
LANGUAGES="en fr it ja tr es pt de"
PATHS="v3/coach/workouts v2/coach/workouts v2/coach/exercise_alternatives"
echo "Logging in"
export ID_TOKEN=`curl --silent -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{
"login": {
"email": "d@t.com",
"password": "r"
}
}' 'https://api.freeletics.com/user/v1/auth/password/login' | jq -r .auth.id_token`
doit() {
HEADERS_FILE=`mktemp`
export OUTPUT_FILE=$1-`echo $2 | tr / -`.json
curl --silent "https://api.freeletics.com/$2?include_deprecated=true" -H "Accept-Language: $1" -H "Authorization: Bearer $ID_TOKEN" -H 'Accept: application/json' -H 'User-Agent: Edward' -D $HEADERS_FILE > $OUTPUT_FILE
export ETAG=`awk '/^ETag: / { print $2 }' $HEADERS_FILE | tr -d ' \t\n\r\f'`
jq -n '{ (env.OUTPUT_FILE): env.ETAG }'
rm -f $HEADERS_FILE
}
export -f doit
echo "Fetching workouts"
ETAGS=`parallel --files doit ::: $LANGUAGES ::: $PATHS`
cat $ETAGS | jq -s add > workouts.json
@catalinaturlea
Copy link

we are missing ?include_deprecated=true in the url for downloading the workouts

@SeriousM
Copy link

SeriousM commented Jan 8, 2018

works like a charm, thank you!

@Maybach91
Copy link

Its not working anymore, isnt it?

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