A live bird collage card for your Home Assistant dashboard.
Apprise - notify each new infrequent visitor
ehpersonal3849a92bae6cc2
diff --git a/scripts/config.php b/scripts/config.phpindex 428df35c..d3a8b6a6 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -170,7 +170,7 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}<label for="apprise_notification_body">Notification Body (use variables $sciname, $comname, or $confidence): </label><input name="apprise_notification_body" type="text" value="<?php print($config['APPRISE_NOTIFICATION_BODY']);?>" /><br><input type="checkbox" name="apprise_notify_new_species" <?php if($config['APPRISE_NOTIFY_NEW_SPECIES'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >- <label for="apprise_notify_new_species">Notify each new species</label><br>+ <label for="apprise_notify_new_species">Notify each new infrequent species detection (<5 visits per week)</label><br><input type="checkbox" name="apprise_notify_each_detection" <?php if($config['APPRISE_NOTIFY_EACH_DETECTION'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> ><label for="apprise_notify_each_detection">Notify each new detection</label><br><br><h3>Bird Photos from Flickr</h3>diff --git a/scripts/server.py b/scripts/server.pyindex f7a8c7b2..dd386b81 100755--- a/scripts/server.py+++ b/scripts/server.py@@ -250,19 +250,19 @@ def sendAppriseNotifications(species, confidence):if str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFY_NEW_SPECIES')]).split('=')[1]).split('\\')[0]) == "1":try:con = sqlite3.connect(userDir + '/BirdNET-Pi/scripts/birds.db')- con.row_factory = lambda cursor, row: row[0]cur = con.cursor()- cur.execute("SELECT DISTINCT(Com_Name) FROM detections")+ cur.execute("SELECT DISTINCT(Com_Name), count(Com_Name) FROM detections WHERE date > (SELECT DATETIME('now', '-7 day')) GROUP BY Com_Name")known_species = cur.fetchall()sciName, comName = species.split("_")+ numberDetections = [d[1] for d in known_species if d[0] == comName.replace("'","")][0]- if comName not in known_species:+ if numberDetections <= 5:apobj = apprise.Apprise()config = apprise.AppriseConfig()config.add(userDir + '/BirdNET-Pi/apprise.txt')apobj.add(config)apobj.notify(- body=body.replace("$sciname", species.split("_")[0]).replace("$comname", species.split("_")[1]).replace("$confidence", confidence),+ body=body.replace("$sciname", species.split("_")[0]).replace("$comname", species.split("_")[1]).replace("$confidence", confidence) + " (only seen "+str(int(numberDetections)+1)+" times in last 7d)",title=title,)