Merge branch 'main' of github.com:mcguirepr89/BirdNET-Pi
This commit is contained in:
+10
-1
@@ -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 "<pre class=\"bash\">".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$cf." ")."</pre>";
|
||||
echo "<pre class=\"bash\">".shell_exec($home."/BirdNET-Pi/birdnet/bin/apprise -vv -t '".$title."' -b '".$body."' ".$attach." ".$cf." ")."</pre>";
|
||||
|
||||
die();
|
||||
}
|
||||
@@ -327,6 +334,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>
|
||||
</dl>
|
||||
<p>Use the variables defined above to customize your notification title and body.</p>
|
||||
<label for="apprise_notification_title">Notification Title: </label>
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
|
||||
if(isset($_GET['date'])){
|
||||
$theDate = $_GET['date'];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
ini_set('session.gc_maxlifetime', 7200);
|
||||
session_set_cookie_params(7200);
|
||||
session_start();
|
||||
|
||||
+8
-7
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
@@ -175,11 +176,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 +326,11 @@ echo "<table>
|
||||
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 +380,11 @@ echo "<table>
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
if(isset($_GET['ajax_csv'])) {
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
ini_set('session.gc_maxlifetime', 7200);
|
||||
session_set_cookie_params(7200);
|
||||
session_start();
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
|
||||
@@ -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,24 @@ 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:
|
||||
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
|
||||
except ValueError:
|
||||
image_url = None
|
||||
else:
|
||||
image_url = flickr_images[comName]
|
||||
|
||||
|
||||
if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1":
|
||||
notify_body = body.replace("$sciname", sciName)\
|
||||
@@ -50,6 +76,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 +89,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 +118,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 +132,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 +165,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 +179,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")
|
||||
|
||||
Reference in New Issue
Block a user