From a2f3d422465ae0d7c590f840b1b44ed38cb7b8dc Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Thu, 14 Jul 2022 12:07:42 -0400
Subject: [PATCH 1/5] clearer language
---
scripts/play.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/play.php b/scripts/play.php
index d0befaf..18a7eb3 100644
--- a/scripts/play.php
+++ b/scripts/play.php
@@ -175,11 +175,11 @@ function toggleLock(filename, type, elem) {
if(this.responseText == "OK"){
if(type == "add") {
elem.setAttribute("src","images/lock.svg");
- elem.setAttribute("title", "This file is delete protected.");
+ elem.setAttribute("title", "This file is excluded from being purged.");
elem.setAttribute("onclick", elem.getAttribute("onclick").replace("add","del"));
} else {
elem.setAttribute("src","images/unlock.svg");
- elem.setAttribute("title", "This file is not delete protected.");
+ elem.setAttribute("title", "This file is not excluded from being purged.");
elem.setAttribute("onclick", elem.getAttribute("onclick").replace("del","add"));
}
}
@@ -325,11 +325,11 @@ echo "
if($config["FULL_DISK"] == "purge") {
if(!in_array($filename_formatted, $disk_check_exclude_arr)) {
$imageicon = "images/unlock.svg";
- $title = "This file is not delete protected.";
+ $title = "This file is not excluded from being purged.";
$type = "add";
} else {
$imageicon = "images/lock.svg";
- $title = "This file is delete protected.";
+ $title = "This file is excluded from being purged.";
$type = "del";
}
@@ -379,11 +379,11 @@ echo "
if($config["FULL_DISK"] == "purge") {
if(!in_array($filename_formatted, $disk_check_exclude_arr)) {
$imageicon = "images/unlock.svg";
- $title = "This file is not delete protected.";
+ $title = "This file is not excluded from being purged.";
$type = "add";
} else {
$imageicon = "images/lock.svg";
- $title = "This file is delete protected.";
+ $title = "This file is excluded from being purged.";
$type = "del";
}
From 98130fa3958d8b4a82dadd6245f0727c5d6af340 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Thu, 14 Jul 2022 16:24:59 -0400
Subject: [PATCH 2/5] #410 Flickr image in notifications
---
scripts/config.php | 2 ++
scripts/utils/notifications.py | 45 ++++++++++++++++++++++++++++------
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/scripts/config.php b/scripts/config.php
index 2aafa7f..d95a9fc 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -327,6 +327,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.
Use the variables defined above to customize your notification title and body.
diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py
index 06dbd10..dfed537 100644
--- a/scripts/utils/notifications.py
+++ b/scripts/utils/notifications.py
@@ -3,21 +3,29 @@ import os
import socket
import sqlite3
from datetime import datetime
+import requests
userDir = os.path.expanduser('~')
APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
-def notify(body, title):
+def notify(body, title, attached=None):
apobj = apprise.Apprise()
config = apprise.AppriseConfig()
config.add(APPRISE_CONFIG)
apobj.add(config)
- apobj.notify(
- body=body,
- title=title,
- )
+ if attached is not None:
+ apobj.notify(
+ body=body,
+ title=title,
+ attach=attached,
+ )
+ else:
+ apobj.notify(
+ body=body,
+ title=title,
+ )
def sendAppriseNotifications(species, confidence, path, date, time, week, latitude, longitude, cutoff, sens, overlap, settings_dict, db_path=DB_PATH):
@@ -37,6 +45,21 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
websiteurl = "http://"+socket.gethostname()+".local"
listenurl = websiteurl+"?filename="+path
+ image_url = None
+ flickr_images = {}
+
+ if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
+ if not comName in flickr_images:
+ # TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here
+ url = 'https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key='+str(settings_dict.get('FLICKR_API_KEY'))+'&text='+str(comName)+'&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1'
+ resp = requests.get(url=url)
+ data = resp.json()["photos"]["photo"][0]
+
+ 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
+ else:
+ image_url = flickr_images[comName]
+
if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1":
notify_body = body.replace("$sciname", sciName)\
@@ -50,6 +73,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)
notify_title = title.replace("$sciname", sciName)\
.replace("$comname", comName)\
@@ -62,8 +86,9 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)
- notify(notify_body, notify_title)
+ notify(notify_body, notify_title, image_url)
APPRISE_NOTIFICATION_NEW_SPECIES_DAILY_COUNT_LIMIT = 1 # Notifies the first N per day.
if settings_dict.get('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY') == "1":
@@ -90,6 +115,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)\
+ " (first time today)"
notify_title = title.replace("$sciname", sciName)\
@@ -103,9 +129,10 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)\
+ " (first time today)"
- notify(notify_body, notify_title)
+ notify(notify_body, notify_title, image_url)
con.close()
except sqlite3.Error as e:
print(e)
@@ -135,6 +162,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)\
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
notify_title = title.replace("$sciname", sciName)\
@@ -148,9 +176,10 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
.replace("$longitude", longitude)\
.replace("$cutoff", cutoff)\
.replace("$sens", sens)\
+ .replace("$flickrimage", "")\
.replace("$overlap", overlap)\
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
- notify(notify_body, notify_title)
+ notify(notify_body, notify_title, image_url)
con.close()
except sqlite3.Error:
print("Database busy")
From 585d666432841ba72b5aedfe1b0d1ab094c0eff0 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Fri, 15 Jul 2022 11:16:54 -0400
Subject: [PATCH 3/5] Handle $flickrimage in test notification
---
scripts/config.php | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/scripts/config.php b/scripts/config.php
index d95a9fc..a4631c0 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -187,6 +187,11 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
$filename = "http://birdnetpi.local/"."?filename=".$filename;
}
+ $attach="";
+ if (strpos($body, '$flickrimage') !== false) {
+ $attach = "--attach https://live.staticflickr.com/7430/27545810581_8bfa8289a3_c.jpg";
+ }
+
$title = str_replace("\$sciname", $sciname, $title);
$title = str_replace("\$comname", $comname, $title);
$title = str_replace("\$confidence", $confidence, $title);
@@ -199,6 +204,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);
$body = str_replace("\$sciname", $sciname, $body);
$body = str_replace("\$comname", $comname, $body);
@@ -212,8 +218,9 @@ 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);
- echo "".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$cf." ")."
";
+ echo "".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$attach." ".$cf." ")."
";
die();
}
From 0c9bc94ae281ebae743efd5eef46120b26ee2779 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Fri, 15 Jul 2022 17:20:01 -0400
Subject: [PATCH 4/5] Display errors
---
scripts/history.php | 5 ++---
scripts/overview.php | 4 ++--
scripts/play.php | 3 ++-
scripts/spectrogram.php | 2 ++
scripts/todays_detections.php | 4 ++--
5 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/scripts/history.php b/scripts/history.php
index 88ca352..09afbd9 100644
--- a/scripts/history.php
+++ b/scripts/history.php
@@ -1,7 +1,6 @@
Date: Fri, 15 Jul 2022 17:26:31 -0400
Subject: [PATCH 5/5] Try/catch Flickr errors
---
scripts/utils/notifications.py | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py
index dfed537..e09cdec 100644
--- a/scripts/utils/notifications.py
+++ b/scripts/utils/notifications.py
@@ -50,13 +50,16 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
if not comName in flickr_images:
- # TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here
- url = 'https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key='+str(settings_dict.get('FLICKR_API_KEY'))+'&text='+str(comName)+'&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1'
- resp = requests.get(url=url)
- data = resp.json()["photos"]["photo"][0]
+ try:
+ # TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here
+ url = 'https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key='+str(settings_dict.get('FLICKR_API_KEY'))+'&text='+str(comName)+'&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1'
+ resp = requests.get(url=url)
+ data = resp.json()["photos"]["photo"][0]
- 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
+ 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
else:
image_url = flickr_images[comName]