Created
March 8, 2017 07:48
-
-
Save manio/50c704be5ab870dc00e42699381f6347 to your computer and use it in GitHub Desktop.
a simple bash script for weight logging automation to myfitnesspal and influxdb
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 | |
# a simple bash script for weight logging automation | |
# more info: https://skyboo.net/2017/03/automate-my-weekly-weight-logging/ | |
if [[ $# -eq 0 ]]; then | |
echo "[*] ERROR: missing weight argument" | |
exit | |
fi | |
echo "[*] **** MyFitnessPal ****" | |
echo "[*] getting auth token from login page..." | |
# Pulls the login page and strips out the auth token | |
authToken=`curl -L -c /dev/shm/cookies.txt --silent 'https://www.myfitnesspal.com/account/login' | grep 'AUTH_TOKEN' | cut -d '"' -f2` | |
echo "[*] got auth token: $authToken" | |
# Posts all the pre-URI-encoded stuff and appends the URI-encoded auth token | |
echo "[*] https logging in..." | |
curl -L -c /dev/shm/cookies.txt -b /dev/shm/cookies.txt --silent -o /dev/null --data 'username=<YOUR_USERNAME_HERE>&password=<YOUR_PASSWORD_HERE>' --data-urlencode authenticity_token=$authToken 'https://www.myfitnesspal.com/account/login' | |
echo "[*] posting weight data..." | |
curl -L -c /dev/shm/cookies.txt -b /dev/shm/cookies.txt --silent --data "weight[display_value]=$1" --data-urlencode authenticity_token=$authToken 'http://www.myfitnesspal.com/measurements/save' | grep "Measurements updated" | |
if [[ $? != 0 ]]; then | |
echo "[*] update failed" | |
else | |
echo "[*] measurements updated successfuly" | |
fi | |
echo "[*] logging out..." | |
curl -L -c /dev/shm/cookies.txt -b /dev/shm/cookies.txt --silent -o /dev/null 'http://www.myfitnesspal.com/account/logout' | |
echo "[*] removing temporary cookies..." | |
rm -f /dev/shm/cookies.txt | |
echo "[*] **** InfluxDB ****" | |
curl -i -XPOST 'http://127.0.0.1:8086/write?db=waga' --data-binary "weight value=$1" | |
echo "[*] script done, launching grafana" | |
x-www-browser '<YOUR_GRAFANA_URL_HERE>/dashboard/db/waga' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment