From 29af308d7d8714372c6cd91ddc01bf14c688fe8b Mon Sep 17 00:00:00 2001 From: frederik Date: Tue, 26 Aug 2025 17:06:45 +0200 Subject: [PATCH] be a bit more image provider agnostic --- scripts/config.php | 20 +++++++++++++------- scripts/utils/notifications.py | 11 ++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/config.php b/scripts/config.php index 3266b2b..6d2e63a 100644 --- a/scripts/config.php +++ b/scripts/config.php @@ -224,9 +224,15 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") { $friendlyfilename = "[Listen here](".$filename.")"; $attach=""; - $exampleimage = "https://live.staticflickr.com/7430/27545810581_8bfa8289a3_c.jpg"; - if (strpos($body, '$flickrimage') !== false) { - $attach = "--attach ".$exampleimage; + if ($config["IMAGE_PROVIDER"] === 'FLICKR') { + $image_provider = new Flickr(); + } else { + $image_provider = new Wikipedia(); + } + $exampleimage = htmlspecialchars_decode($image_provider->get_image($sciname)['image_url'], ENT_QUOTES); + + if (strpos($body, '$image') !== false) { + $attach = "--attach '$exampleimage'"; } if (strpos($body, '{') === false) { $exampleimage = ""; @@ -246,7 +252,7 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") { $title = str_replace("\$cutoff", $cutoff, $title); $title = str_replace("\$sens", $sens, $title); $title = str_replace("\$overlap", $overlap, $title); - $title = str_replace("\$flickrimage", $exampleimage, $title); + $title = str_replace("\$image", $exampleimage, $title); $title = str_replace("\$reason", 'Test message', $title); $body = str_replace("\$sciname", $sciname, $body); @@ -263,7 +269,7 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") { $body = str_replace("\$cutoff", $cutoff, $body); $body = str_replace("\$sens", $sens, $body); $body = str_replace("\$overlap", $overlap, $body); - $body = str_replace("\$flickrimage", $exampleimage, $body); + $body = str_replace("\$image", $exampleimage, $body); $body = str_replace("\$reason", 'Test message', $body); $temp = tmpfile(); @@ -522,8 +528,8 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
Sigmoid Sensitivity set in "Advanced Settings"
$overlap
Overlap set in "Advanced Settings"
-
$flickrimage
-
A preview image of the detected species from Flickr. Set your API key below.
+
$image
+
An image of the detected species from a photo source, see below.
$reason
The reason a notification was sent
diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index 3b8c905..3ead8ab 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -11,7 +11,7 @@ userDir = os.path.expanduser('~') APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt' DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db' -flickr_images = {} +images = {} species_last_notified = {} @@ -59,6 +59,7 @@ def sendAppriseNotifications(species, confidence, confidencepct, path, .replace("$cutoff", cutoff) \ .replace("$sens", sens) \ .replace("$flickrimage", image_url if "{" in body else "") \ + .replace("$image", image_url if "{" in body else "") \ .replace("$overlap", overlap) \ .replace("$reason", reason) return ret @@ -102,17 +103,17 @@ def sendAppriseNotifications(species, confidence, confidencepct, path, friendlyurl = "[Listen here]("+listenurl+")" image_url = "" - if "$flickrimage" in body: - if comName not in flickr_images: + if "$flickrimage" in body or "$image" in body: + if comName not in images: try: url = f"http://localhost/api/v1/image/{sciName}" resp = requests.get(url=url, timeout=10).json() - flickr_images[comName] = resp['data']['image_url'] + images[comName] = resp['data']['image_url'] except Exception as e: print("FLICKR API ERROR: "+str(e)) image_url = "" else: - image_url = flickr_images[comName] + image_url = images[comName] if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1": notify_body = render_template(body, "detection")