A live bird collage card for your Home Assistant dashboard.
read body from file
frederikabf350107cd5
diff --git a/scripts/config.php b/scripts/config.phpindex 6d2e63a6..93ec9299 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -17,6 +17,12 @@ if (file_exists($home."/BirdNET-Pi/apprise.txt")) {$apprise_config = "";}+if (file_exists($home."/BirdNET-Pi/message.txt")) {+ $apprise_notification_body = file_get_contents($home."/BirdNET-Pi/message.txt");+} else {+ $apprise_notification_body = "";+}+function syslog_shell_exec($cmd, $sudo_user = null) {if ($sudo_user) {$cmd = "sudo -u $sudo_user $cmd";@@ -138,7 +144,6 @@ if(isset($_GET["latitude"])){$contents = preg_replace("/LONGITUDE=.*/", "LONGITUDE=$longitude", $contents);$contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id", $contents);$contents = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents);- $contents = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents);$contents = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents);$contents = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents);$contents = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=.*/", "APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=$apprise_notify_new_species_each_day", $contents);@@ -177,6 +182,10 @@ if(isset($_GET["latitude"])){fwrite($appriseconfig, $apprise_input);$apprise_config = $apprise_input;}+ if(isset($apprise_notification_body)){+ $apprisebody = fopen($home."/BirdNET-Pi/message.txt", "w");+ fwrite($apprisebody, $apprise_notification_body);+ }if ($model != $config['MODEL'] || $language != $config['DATABASE_LANG']){if(strlen($language) == 2){syslog_shell_exec("$home/BirdNET-Pi/scripts/install_language_label.sh", $user);@@ -537,7 +546,7 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}<label for="apprise_notification_title">Notification Title: </label><input name="apprise_notification_title" style="width: 100%" type="text" value="<?php print($config['APPRISE_NOTIFICATION_TITLE']);?>" /><br><label for="apprise_notification_body">Notification Body: </label>- <input name="apprise_notification_body" style="width: 100%" type="text" value='<?php print($config['APPRISE_NOTIFICATION_BODY']);?>' /><br>+ <textarea name="apprise_notification_body" style="width: 100%" rows="5" type="text" ><?php print($apprise_notification_body);?></textarea><input type="checkbox" name="apprise_notify_new_species" <?php if($config['APPRISE_NOTIFY_NEW_SPECIES'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> ><label for="apprise_notify_new_species">Notify each new infrequent species detection (<5 visits per week)</label><br><input type="checkbox" name="apprise_notify_new_species_each_day" <?php if($config['APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.pyindex 3ead8ab8..70e07964 100644--- a/scripts/utils/notifications.py+++ b/scripts/utils/notifications.py@@ -9,6 +9,7 @@ import time as timeimuserDir = os.path.expanduser('~')APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'+APPRISE_BODY = userDir + '/BirdNET-Pi/body.txt'DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'images = {}@@ -68,7 +69,9 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,if os.path.exists(APPRISE_CONFIG) and os.path.getsize(APPRISE_CONFIG) > 0:title = html.unescape(settings_dict.get('APPRISE_NOTIFICATION_TITLE'))- body = html.unescape(settings_dict.get('APPRISE_NOTIFICATION_BODY'))+ f = open(APPRISE_BODY, 'r')+ body = f.read()+sciName, comName = species.split("_")APPRISE_ONLY_NOTIFY_SPECIES_NAMES = settings_dict.get('APPRISE_ONLY_NOTIFY_SPECIES_NAMES')@@ -110,10 +113,8 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,resp = requests.get(url=url, timeout=10).json()images[comName] = resp['data']['image_url']except Exception as e:- print("FLICKR API ERROR: "+str(e))- image_url = ""- else:- image_url = images[comName]+ print("IMAGE API ERROR: "+str(e))+ image_url = images.get(comName, "")if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1":notify_body = render_template(body, "detection")