fix: enable sending test notifications with an empty db
This commit is contained in:
+1
-16
@@ -197,24 +197,10 @@ if(isset($_GET["latitude"])){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
|
if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
|
||||||
$db = new SQLite3($home."/BirdNET-Pi/scripts/birds.db", SQLITE3_OPEN_READONLY);
|
|
||||||
$db->busyTimeout(1000);
|
|
||||||
$statement0 = $db->prepare('SELECT * FROM detections ORDER BY Date DESC, Time DESC LIMIT 1');
|
|
||||||
$result0 = $statement0->execute();
|
|
||||||
while($todaytable=$result0->fetchArray(SQLITE3_ASSOC))
|
|
||||||
{
|
|
||||||
$detection = json_encode($todaytable);
|
|
||||||
}
|
|
||||||
|
|
||||||
$conf = $_GET['apprise_config'];
|
$conf = $_GET['apprise_config'];
|
||||||
$title = $_GET['apprise_notification_title'];
|
$title = $_GET['apprise_notification_title'];
|
||||||
$body = $_GET['apprise_notification_body'];
|
$body = $_GET['apprise_notification_body'];
|
||||||
|
|
||||||
$temp_det = tmpfile();
|
|
||||||
$t_det_path = stream_get_meta_data($temp_det)['uri'];
|
|
||||||
chmod($t_det_path, 0644);
|
|
||||||
fwrite($temp_det, $detection);
|
|
||||||
|
|
||||||
$temp_conf = tmpfile();
|
$temp_conf = tmpfile();
|
||||||
$t_conf_path = stream_get_meta_data($temp_conf)['uri'];
|
$t_conf_path = stream_get_meta_data($temp_conf)['uri'];
|
||||||
chmod($t_conf_path, 0644);
|
chmod($t_conf_path, 0644);
|
||||||
@@ -225,10 +211,9 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
|
|||||||
chmod($t_body_path, 0644);
|
chmod($t_body_path, 0644);
|
||||||
fwrite($temp_body, $body);
|
fwrite($temp_body, $body);
|
||||||
|
|
||||||
$cmd = "sudo -u $user $home/BirdNET-Pi/birdnet/bin/python3 $home/BirdNET-Pi/scripts/send_test_notification.py --body $t_body_path --config $t_conf_path --title '" . escapeshellcmd($title) . "' --detection $t_det_path 2>&1";
|
$cmd = "sudo -u $user $home/BirdNET-Pi/birdnet/bin/python3 $home/BirdNET-Pi/scripts/send_test_notification.py --body $t_body_path --config $t_conf_path --title '" . escapeshellcmd($title) . "' 2>&1";
|
||||||
$ret = shell_exec($cmd);
|
$ret = shell_exec($cmd);
|
||||||
echo "<pre class=\"bash\">".$ret."</pre>";
|
echo "<pre class=\"bash\">".$ret."</pre>";
|
||||||
fclose($temp_det);
|
|
||||||
fclose($temp_conf);
|
fclose($temp_conf);
|
||||||
fclose($temp_body);
|
fclose($temp_body);
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from utils import notifications
|
from utils import notifications
|
||||||
from utils.helpers import DB_PATH, get_settings
|
from utils.helpers import get_settings
|
||||||
|
from utils.db import get_latest
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--config', help='path to config', required=True)
|
parser.add_argument('--config', help='path to config', required=True)
|
||||||
parser.add_argument('--title', help='title', required=True)
|
parser.add_argument('--title', help='title', required=True)
|
||||||
parser.add_argument('--body', help='path to body template', required=True)
|
parser.add_argument('--body', help='path to body template', required=True)
|
||||||
parser.add_argument('--detection', help='path to json encoded detection', required=True)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
conf = get_settings()
|
conf = get_settings()
|
||||||
@@ -23,9 +23,6 @@ if __name__ == "__main__":
|
|||||||
notifications.APPRISE_CONFIG = args.config
|
notifications.APPRISE_CONFIG = args.config
|
||||||
notifications.APPRISE_BODY = args.body
|
notifications.APPRISE_BODY = args.body
|
||||||
|
|
||||||
f = open(args.detection, 'r')
|
|
||||||
d = json.loads(f.read())
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")
|
formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")
|
||||||
handler = logging.StreamHandler(stream=sys.stdout)
|
handler = logging.StreamHandler(stream=sys.stdout)
|
||||||
@@ -33,7 +30,14 @@ if __name__ == "__main__":
|
|||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
notifications.sendAppriseNotifications(d['Sci_Name'], d['Com_Name'], d['Confidence'],
|
d = get_latest()
|
||||||
round(d['Confidence'] * 100), d['File_Name'],
|
if not d:
|
||||||
d['Date'], d['Time'], d['Week'], d['Lat'], d['Lon'], d['Cutoff'],
|
now = datetime.datetime.now()
|
||||||
d['Sens'], d['Overlap'], dict(conf), DB_PATH)
|
d = {'Sci_Name': 'Aptenodytes patagonicus', 'Com_Name': 'King Penguin', 'Confidence': 0.84, 'File_Name': 'this_is_not_a_file.mp3',
|
||||||
|
'Date': now.strftime('%Y-%m-%d'), 'Time': now.strftime("%H:%M:%S"), 'Week': now.isocalendar()[1],
|
||||||
|
'Lat': conf.getfloat('LATITUDE'), 'Lon': conf.getfloat('LONGITUDE'), 'Cutoff': conf.getfloat('CONFIDENCE'),
|
||||||
|
'Sens': conf.getfloat('SENSITIVITY'), 'Overlap': conf.getfloat('OVERLAP')}
|
||||||
|
|
||||||
|
notifications.sendAppriseNotifications(d['Sci_Name'], d['Com_Name'], d['Confidence'], round(d['Confidence'] * 100), d['File_Name'], d['Date'],
|
||||||
|
d['Time'], d['Week'], d['Lat'], d['Lon'], d['Cutoff'], d['Sens'], d['Overlap'], dict(conf))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user