Last active
October 19, 2020 15:43
-
-
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.
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
#!/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 |
works like a charm, thank you!
Its not working anymore, isnt it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
we are missing
?include_deprecated=true
in the url for downloading the workouts