A live bird collage card for your Home Assistant dashboard.
fix: enable sending test notifications with an empty db
frederikd154b5f6f1b6
diff --git a/scripts/config.php b/scripts/config.phpindex 3798c83b..1e5e6ef3 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -197,24 +197,10 @@ if(isset($_GET["latitude"])){}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'];$title = $_GET['apprise_notification_title'];$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();$t_conf_path = stream_get_meta_data($temp_conf)['uri'];chmod($t_conf_path, 0644);@@ -225,10 +211,9 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {chmod($t_body_path, 0644);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);echo "<pre class=\"bash\">".$ret."</pre>";- fclose($temp_det);fclose($temp_conf);fclose($temp_body);diff --git a/scripts/send_test_notification.py b/scripts/send_test_notification.pyindex edda6ac1..9974b189 100755--- a/scripts/send_test_notification.py+++ b/scripts/send_test_notification.py@@ -1,17 +1,17 @@import argparse-import json+import datetimeimport loggingimport sysfrom utils import notifications-from utils.helpers import DB_PATH, get_settings+from utils.helpers import get_settings+from utils.db import get_latestif __name__ == "__main__":parser = argparse.ArgumentParser()parser.add_argument('--config', help='path to config', required=True)parser.add_argument('--title', help='title', 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()conf = get_settings()@@ -23,9 +23,6 @@ if __name__ == "__main__":notifications.APPRISE_CONFIG = args.confignotifications.APPRISE_BODY = args.body- f = open(args.detection, 'r')- d = json.loads(f.read())-logger = logging.getLogger()formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")handler = logging.StreamHandler(stream=sys.stdout)@@ -33,7 +30,14 @@ if __name__ == "__main__":logger.addHandler(handler)logger.setLevel(logging.INFO)- 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), DB_PATH)+ d = get_latest()+ if not d:+ now = datetime.datetime.now()+ 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))+