diff --git a/scripts/config.php b/scripts/config.php index 6d2e63a..93ec929 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}
- ' />
+ >
> diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index 3ead8ab..70e0796 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -9,6 +9,7 @@ import time as timeim userDir = 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")