Files
AvianVisitors/scripts/species_notifier.sh
T
Patrick McGuire ae3e29ef1d seems to work
2021-10-15 19:48:39 -04:00

33 lines
884 B
Bash
Executable File

#!/usr/bin/env bash
# Sends a notification if a new species is detected
#set -x
trap 'rm -f $tmpids' EXIT
source /etc/birdnet/birdnet.conf
tmpids=$(mktemp)
[ -f ${IDFILE} ] || touch ${IDFILE}
cat "${IDFILE}" > "${tmpids}"
/usr/local/bin/update_species.sh > /dev/null
if ! diff "${IDFILE}" "${tmpids}" &> /dev/null; then
SPECIES=("$(diff "${IDFILE}" "${tmpids}" \
| grep "Common Name" \
| sort \
| awk '{for(i=4;i<=NF;++i)printf $i""FS ; print ""}')")
NOTIFICATION="New Species Detection: "${SPECIES[@]}""
echo "Sending the following notification:
${NOTIFICATION}"
if [ ! -z ${PUSHED_APP_KEY} ];then
curl -X POST \
--form-string "app_key=${PUSHED_APP_KEY}" \
--form-string "app_secret=${PUSHED_APP_SECRET}" \
--form-string "target_type=app" \
--form-string "content=${NOTIFICATION}" \
https://api.pushed.co/1/push
fi
fi