Created
December 24, 2018 11:29
-
-
Save porjo/4188cd8c7cb158afb6400a76d5cc5598 to your computer and use it in GitHub Desktop.
Argos / Bitbar shell script for fetching Exetel usage stats
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
#!/usr/bin/env bash | |
echo "Exetel" | |
echo "---" | |
USERNAME="076543210" | |
PASSWORD="xxxxx" | |
MinAge=5 | |
COOKIE="/tmp/exetel.cookies" | |
JSON="/tmp/exetel.json" | |
[ ! -f $COOKIE ] && touch $COOKIE | |
[ ! -f $JSON ] && touch $JSON | |
ErrorMsg="" | |
UsedMsg="" | |
function Login { | |
test `find $COOKIE -mmin -$MinAge` && return | |
curl -s -c $COOKIE -o /dev/null -F "username=$USERNAME" -F "password=$PASSWORD" https://www.exetel.com.au/myexetel/login/user_login | |
[ $? -ne 0 ] && echo "Error logging in" && exit 1 | |
} | |
function FetchUsage { | |
curl -s -b $COOKIE -F "service_number=$USERNAME" -w "%{http_code}" -o $JSON "https://www.exetel.com.au/myexetel/services/service_usage_adsl_dashboard/$USERNAME" | |
[ $? -ne 0 ] && echo "Error fetching data" && exit 1 | |
} | |
if test `find $JSON -mmin +$MinAge`; then | |
HTTP_STATUS=$(FetchUsage) | |
if [ "$HTTP_STATUS" -ne 200 ]; then | |
Login | |
FetchUsage > /dev/null | |
fi | |
fi | |
FETCHED=$(date -d "`stat $JSON | grep Modify | cut -f2- -d:`" +%c) | |
USED=`cat $JSON | jq .[1]` | |
TOTAL=`cat $JSON | jq .[2] | tr -d '"'` | |
UsedMsg="Used $USED of $TOTAL" | |
if [ "$ARGOS_MENU_OPEN" == "true" ]; then | |
echo $FETCHED | |
echo $UsedMsg | |
else | |
echo "Loading..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment