From 5fdc721ad7c4f23eccfb22a24156c692c8e622e9 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:26:49 -0400 Subject: [PATCH] better $flickrimage handling with JSON --- scripts/config.php | 10 +++++++--- scripts/utils/notifications.py | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/config.php b/scripts/config.php index a4631c0..d55c2d0 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 "
".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$attach." ".$cf." ")."
"; diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index e09cdec..f451b5b 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)