-
-
Save SeriousM/e5b754a9cee5141f7a7359329437e08d 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 hidden or 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 | |
[email protected] | |
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": "[email protected]", | |
"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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment