Skip to content

A live bird collage card for your Home Assistant dashboard.

fixed pushed.co notifications

Patrick McGuirecc01f8cd09b0
diff --git a/scripts/species_notifier.sh b/scripts/species_notifier.sh
index f00cecb3..5a2bec56 100755
--- a/scripts/species_notifier.sh
+++ b/scripts/species_notifier.sh
@@ -1,25 +1,24 @@
#!/usr/bin/env bash
# Sends a notification if a new species is detected
-set -x
-trap 'rm -f $tmpids' EXIT
-
+#set -x
+trap 'rm -f $lastcheck' EXIT
source /etc/birdnet/birdnet.conf
-lastcheck="${IDFILE}.lastime"
-[ -f ${IDFILE} ] || touch ${IDFILE}
-cat "${IDFILE}" > "${lastcheck}"
+lastcheck="$(mktemp)"
+
+cp ${IDFILE} ${lastcheck}
+
+/home/pi/BirdNET-Pi/scripts/new_update_species.sh
-/usr/local/bin/update_species.sh > /dev/null
+if ! diff ${IDFILE} ${lastcheck} &> /dev/null;then
+ SPECIES=$(diff ${IDFILE} ${lastcheck} \
+ | tail -n+2 |\
+ awk '{for(i=2;i<=NF;++i)printf $i""FS ; print ""}' )
-if ! diff "${IDFILE}" "${lastcheck}" &> /dev/null; then
- SPECIES=("$(diff "${IDFILE}" "${lastcheck}" \
- | 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}" \
@@ -29,3 +28,4 @@ ${NOTIFICATION}"
https://api.pushed.co/1/push
fi
fi
+
diff --git a/scripts/update_species.sh b/scripts/update_species.sh
index 04842750..cc4b945e 100755
--- a/scripts/update_species.sh
+++ b/scripts/update_species.sh
@@ -2,19 +2,13 @@
# Update the species list
#set -x
trap 'rm -f "$TMPFILE"' EXIT
-
source /etc/birdnet/birdnet.conf
-
-TMPFILE=$(mktemp) || exit 1
-
-[ -f ${IDFILE} ] || touch ${IDFILE}
-
-if [ $(find ${PROCESSED} -name '*csv' | wc -l) -ge 1 ] &> /dev/null;then
- sort $(find ${PROCESSED} ${ANALYZED} ${EXTRACTED} -name '*csv') \
- | awk -F\; '!/Scientific/ {print"Common Name: " $4 "\nScientific Name: " $3""}' \
- | uniq > "$TMPFILE"
- cat "$TMPFILE" | awk '!visited[$0]++' > "$IDFILE"
- cat "$IDFILE"
-else
- cat "$IDFILE"
-fi
+db=birds
+dbuser=birder
+dbpassword=${DB_PWD}
+
+mysql -u${dbuser} -p${dbpassword} ${db} \
+ -e 'SELECT Com_Name
+ FROM detections
+ GROUP BY Com_Name' |\
+ tail -n+2 > ${IDFILE}