Created
February 1, 2019 16:39
-
-
Save ke4roh/113e60a3f0deebfc441f8a5968babf11 to your computer and use it in GitHub Desktop.
Monitor the charging station at the Raleigh City Center parking deck and report its status to Google Chat
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 | |
. ./.cccreds | |
function ccstatus { | |
curl -X POST \ | |
http://periscope.raleighnc.gov/periscopeApi/sustainability.getEvFocusXml \ | |
--data-binary '<str name="val" val="" />' \ | |
-H 'Content-type: text/xml' \ | |
--compressed \ | |
--output - --silent | \ | |
xpath -q -e '//s[@name="City Center"]/@status' | \ | |
cut -f 2 -d\" || : | |
} | |
LAST_STATUS=$(ccstatus 2>/dev/null) | |
NO_DATA_COUNTER=0 | |
echo `date` $LAST_STATUS | |
while true; do | |
STATUS=$(ccstatus 2>/dev/null) | |
if [ -z "$STATUS" ] ; then | |
NO_DATA_COUNTER=$((NO_DATA_COUNTER+1)) | |
if [ "$NO_DATA_COUNTER" -gt 10 ] ; then | |
# Until 5 minutes has passed, we'll just ignore the no data errors. After that, it becomes reportable | |
STATUS="No data" | |
fi | |
else | |
NO_DATA_COUNTER=0 | |
fi | |
if [ ! -z "$STATUS" ] && [ "$LAST_STATUS" != "$STATUS" ] ; then | |
echo `date` $STATUS | |
# curl "$IFTTT_ENDPOINT" --silent -X POST -H 'Content-type: application/json' --data-binary "{\"value1\":\"${STATUS}\"}" >/dev/null | |
curl "$GCHAT_ENDPOINT" --silent -X POST -H "Content-type:application/json" --data-binary "{\"thread\":{\"name\":\"spaces/AAAAQm3fN4s/threads/WQsgXxKwsmI\"},\"text\":\ | |
"${STATUS}\"}" >/dev/null | |
LAST_STATUS="$STATUS" | |
fi | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment