Skip to content

A live bird collage card for your Home Assistant dashboard.

better $flickrimage handling with JSON

ehpersonal385fdc721ad7c4
diff --git a/scripts/config.php b/scripts/config.php
index a4631c02..d55c2d04 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -188,8 +188,12 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
}
$attach="";
+ $exampleimage = "https://live.staticflickr.com/7430/27545810581_8bfa8289a3_c.jpg";
if (strpos($body, '$flickrimage') !== false) {
- $attach = "--attach https://live.staticflickr.com/7430/27545810581_8bfa8289a3_c.jpg";
+ $attach = "--attach ".$exampleimage;
+ }
+ if (strpos($body, '{') === false) {
+ $exampleimage = "";
}
$title = str_replace("\$sciname", $sciname, $title);
@@ -204,7 +208,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", "", $title);
+ $title = str_replace("\$flickrimage", $exampleimage, $title);
$body = str_replace("\$sciname", $sciname, $body);
$body = str_replace("\$comname", $comname, $body);
@@ -218,7 +222,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", "", $body);
+ $body = str_replace("\$flickrimage", $exampleimage, $body);
echo "<pre class=\"bash\">".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$attach." ".$cf." ")."</pre>";
diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py
index e09cdecb..f451b5b0 100644
--- a/scripts/utils/notifications.py
+++ b/scripts/utils/notifications.py
@@ -10,12 +10,12 @@ APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
-def notify(body, title, attached=None):
+def notify(body, title, attached=""):
apobj = apprise.Apprise()
config = apprise.AppriseConfig()
config.add(APPRISE_CONFIG)
apobj.add(config)
- if attached is not None:
+ if attached != "":
apobj.notify(
body=body,
title=title,
@@ -45,7 +45,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
websiteurl = "http://"+socket.gethostname()+".local"
listenurl = websiteurl+"?filename="+path
- image_url = None
+ image_url = ""
flickr_images = {}
if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
@@ -59,7 +59,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
image_url = 'https://farm'+str(data["farm"])+'.static.flickr.com/'+str(data["server"])+'/'+str(data["id"])+'_'+str(data["secret"])+'_n.jpg'
flickr_images[comName] = image_url
except ValueError:
- image_url = None
+ image_url = ""
else:
image_url = flickr_images[comName]
@@ -76,7 +76,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)
notify_title = title.replace("$sciname", sciName)\
.replace("$comname", comName)\
@@ -89,7 +89,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)
notify(notify_body, notify_title, image_url)
@@ -118,7 +118,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)\
+ " (first time today)"
notify_title = title.replace("$sciname", sciName)\
@@ -132,7 +132,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)\
+ " (first time today)"
notify(notify_body, notify_title, image_url)
@@ -165,7 +165,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)\
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
notify_title = title.replace("$sciname", sciName)\
@@ -179,7 +179,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
- .replace("$flickrimage", "")\
+ .replace("$flickrimage", image_url if "{" in body else "")\
.replace("$overlap", overlap)\
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
notify(notify_body, notify_title, image_url)