read body from file
This commit is contained in:
+11
-2
@@ -17,6 +17,12 @@ if (file_exists($home."/BirdNET-Pi/apprise.txt")) {
|
|||||||
$apprise_config = "";
|
$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) {
|
function syslog_shell_exec($cmd, $sudo_user = null) {
|
||||||
if ($sudo_user) {
|
if ($sudo_user) {
|
||||||
$cmd = "sudo -u $sudo_user $cmd";
|
$cmd = "sudo -u $sudo_user $cmd";
|
||||||
@@ -138,7 +144,6 @@ if(isset($_GET["latitude"])){
|
|||||||
$contents = preg_replace("/LONGITUDE=.*/", "LONGITUDE=$longitude", $contents);
|
$contents = preg_replace("/LONGITUDE=.*/", "LONGITUDE=$longitude", $contents);
|
||||||
$contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id", $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_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_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=.*/", "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);
|
$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);
|
fwrite($appriseconfig, $apprise_input);
|
||||||
$apprise_config = $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 ($model != $config['MODEL'] || $language != $config['DATABASE_LANG']){
|
||||||
if(strlen($language) == 2){
|
if(strlen($language) == 2){
|
||||||
syslog_shell_exec("$home/BirdNET-Pi/scripts/install_language_label.sh", $user);
|
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>
|
<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>
|
<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>
|
<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"; };?> >
|
<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>
|
<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"; };?> >
|
<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"; };?> >
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import time as timeim
|
|||||||
|
|
||||||
userDir = os.path.expanduser('~')
|
userDir = os.path.expanduser('~')
|
||||||
APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
|
APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
|
||||||
|
APPRISE_BODY = userDir + '/BirdNET-Pi/body.txt'
|
||||||
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
||||||
|
|
||||||
images = {}
|
images = {}
|
||||||
@@ -68,7 +69,9 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,
|
|||||||
if os.path.exists(APPRISE_CONFIG) and os.path.getsize(APPRISE_CONFIG) > 0:
|
if os.path.exists(APPRISE_CONFIG) and os.path.getsize(APPRISE_CONFIG) > 0:
|
||||||
|
|
||||||
title = html.unescape(settings_dict.get('APPRISE_NOTIFICATION_TITLE'))
|
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("_")
|
sciName, comName = species.split("_")
|
||||||
|
|
||||||
APPRISE_ONLY_NOTIFY_SPECIES_NAMES = settings_dict.get('APPRISE_ONLY_NOTIFY_SPECIES_NAMES')
|
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()
|
resp = requests.get(url=url, timeout=10).json()
|
||||||
images[comName] = resp['data']['image_url']
|
images[comName] = resp['data']['image_url']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FLICKR API ERROR: "+str(e))
|
print("IMAGE API ERROR: "+str(e))
|
||||||
image_url = ""
|
image_url = images.get(comName, "")
|
||||||
else:
|
|
||||||
image_url = images[comName]
|
|
||||||
|
|
||||||
if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1":
|
if settings_dict.get('APPRISE_NOTIFY_EACH_DETECTION') == "1":
|
||||||
notify_body = render_template(body, "detection")
|
notify_body = render_template(body, "detection")
|
||||||
|
|||||||
Reference in New Issue
Block a user