Apprise - notify each new infrequent visitor
This commit is contained in:
+1
-1
@@ -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>
|
||||
|
||||
+4
-4
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user