Skip to content

A live bird collage card for your Home Assistant dashboard.

be a bit more image provider agnostic

frederik29af308d7d87
diff --git a/scripts/config.php b/scripts/config.php
index 3266b2ba..6d2e63a6 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}
<dd>Sigmoid Sensitivity set in "Advanced Settings"</dd>
<dt>$overlap</dt>
<dd>Overlap set in "Advanced Settings"</dd>
- <dt>$flickrimage</dt>
- <dd>A preview image of the detected species from Flickr. Set your API key below.</dd>
+ <dt>$image</dt>
+ <dd>An image of the detected species from a photo source, see below.</dd>
<dt>$reason</dt>
<dd>The reason a notification was sent</dd>
</dl>
diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py
index 3b8c905d..3ead8ab8 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")