From fac374e941daefca619ebf316b7fb8b7ea80030b Mon Sep 17 00:00:00 2001 From: Bdoner Date: Wed, 22 Feb 2023 10:37:57 +0100 Subject: [PATCH] Add $confidencepct variable to apprise notification. --- scripts/config.php | 6 ++++-- scripts/server.py | 1 + scripts/utils/notifications.py | 8 +++++++- tests/test_apprise_notifications.py | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/config.php b/scripts/config.php index 9d4adb9..0c6108e 100644 --- a/scripts/config.php +++ b/scripts/config.php @@ -512,6 +512,8 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
Common Name
$confidence
Confidence Score
+
$confidencepct
+
Confidence Score as a percentage (eg. 0.91 => 91)
$listenurl
A link to the detection
$date
@@ -535,9 +537,9 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}

Use the variables defined above to customize your notification title and body.

-
+
- ' />
+ ' />
>
> diff --git a/scripts/server.py b/scripts/server.py index 7e478df..d29904a 100755 --- a/scripts/server.py +++ b/scripts/server.py @@ -485,6 +485,7 @@ def handle_client(conn, addr): settings_dict = config_to_settings(userDir + '/BirdNET-Pi/scripts/thisrun.txt') sendAppriseNotifications(species, str(score), + str(round(score * 100)), File_Name, Date, Time, diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index 304f0d7..958044e 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -38,7 +38,7 @@ def notify(body, title, attached=""): ) -def sendAppriseNotifications(species, confidence, path, date, time, week, latitude, longitude, cutoff, sens, overlap, settings_dict, db_path=DB_PATH): +def sendAppriseNotifications(species, confidence, confidencepct, path, date, time, week, latitude, longitude, cutoff, sens, overlap, settings_dict, db_path=DB_PATH): # print(sendAppriseNotifications) # print(settings_dict) if os.path.exists(APPRISE_CONFIG) and os.path.getsize(APPRISE_CONFIG) > 0: @@ -90,6 +90,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_body = body.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ @@ -103,6 +104,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_title = title.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ @@ -133,6 +135,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_body = body.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ @@ -147,6 +150,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_title = title.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ @@ -181,6 +185,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_body = body.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ @@ -195,6 +200,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu notify_title = title.replace("$sciname", sciName)\ .replace("$comname", comName)\ .replace("$confidence", confidence)\ + .replace("$confidencepct", confidencepct)\ .replace("$listenurl", listenurl)\ .replace("$date", date)\ .replace("$time", time)\ diff --git a/tests/test_apprise_notifications.py b/tests/test_apprise_notifications.py index 0041e43..0dd666d 100644 --- a/tests/test_apprise_notifications.py +++ b/tests/test_apprise_notifications.py @@ -50,6 +50,7 @@ def test_notifications(mocker): "APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY": "0" } sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", + "0.91", "91", "filename", "1666-06-06", @@ -70,6 +71,7 @@ def test_notifications(mocker): notify_call.reset_mock() settings_dict["APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY"] = "1" sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", + "0.91", "91", "filename", "1666-06-06", @@ -92,6 +94,7 @@ def test_notifications(mocker): notify_call.reset_mock() settings_dict["APPRISE_NOTIFY_NEW_SPECIES"] = "1" sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", + "0.91", "91", "filename", "1666-06-06", @@ -117,6 +120,7 @@ def test_notifications(mocker): notify_call.reset_mock() settings_dict["APPRISE_NOTIFY_EACH_DETECTION"] = "1" sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", + "0.91", "91", "filename", "1666-06-06",