#!/bin/bash
###
# $1 = Date (Events must be specified in UTC)
# $2 = Event
# $3 = BOTID
###
if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters"
echo " $0 <date> <event text> <botid>"
echo " date format = 2018-09-22 15:00:00"
exit
fi
GROUPME_URL="https://api.groupme.com/v3/bots/post"
NOW_SECS=$((10#$(date +%s)))
DATE="$1"
EVENT="$2"
BOTID="$3"
DATE_SECS=$((10#$(date -d "${DATE}" +%s)))
DAYS=$(((DATE_SECS-NOW_SECS)/86400))
if [ $DAYS -lt "0" ]; then
exit
fi
if [ $DAYS -lt "3" ]; then
DELTA_HR=$(((DATE_SECS-NOW_SECS)/3600 ))
if [ $DELTA_HR -ge "0" ]; then
MESSAGE="$DELTA_HR hours till ${EVENT}"
else
exit
fi
else
MESSAGE="$DAYS days till ${EVENT}"
fi
# Optional log to syslog
#logger -t groupme "{\"bot_id\": \"$BOTID\", \"text\": \"$MESSAGE\"}"
curl -s -X POST -d "{\"bot_id\": \"$BOTID\", \"text\": \"$MESSAGE\"}" $GROUPME_URL >/dev/null
#logger -t groupme "api.groupme.com returns $?"