Merge pull request #306 from mcguirepr89/apprise_notify_new_species
Apprise notify new species
This commit is contained in:
@@ -60,7 +60,8 @@ RTSP_STREAM=
|
|||||||
|
|
||||||
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
|
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
|
||||||
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
|
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
|
||||||
APPRISE_NOTIFY_EACH_DETECTION=false
|
APPRISE_NOTIFY_EACH_DETECTION=0
|
||||||
|
APPRISE_NOTIFY_NEW_SPECIES=0
|
||||||
|
|
||||||
#---------------------- Flickr Images API Configuration -----------------------#
|
#---------------------- Flickr Images API Configuration -----------------------#
|
||||||
|
|
||||||
|
|||||||
@@ -250,10 +250,6 @@ if(isset($_GET['view'])){
|
|||||||
'sudo systemctl restart spectrogram_viewer.service',
|
'sudo systemctl restart spectrogram_viewer.service',
|
||||||
'sudo systemctl disable --now spectrogram_viewer.service',
|
'sudo systemctl disable --now spectrogram_viewer.service',
|
||||||
'sudo systemctl enable --now spectrogram_viewer.service',
|
'sudo systemctl enable --now spectrogram_viewer.service',
|
||||||
'sudo systemctl stop pushed_notifications.service',
|
|
||||||
'sudo systemctl restart pushed_notifications.service',
|
|
||||||
'sudo systemctl disable --now pushed_notifications.service',
|
|
||||||
'sudo systemctl enable --now pushed_notifications.service',
|
|
||||||
'stop_core_services.sh',
|
'stop_core_services.sh',
|
||||||
'restart_services.sh',
|
'restart_services.sh',
|
||||||
'sudo reboot',
|
'sudo reboot',
|
||||||
|
|||||||
+7
-5
@@ -16,10 +16,10 @@ if(isset($_GET['apprise_notify_each_detection'])) {
|
|||||||
} else {
|
} else {
|
||||||
$apprise_notify_each_detection = 0;
|
$apprise_notify_each_detection = 0;
|
||||||
}
|
}
|
||||||
if(isset($_GET['apprise_notify_each_species'])) {
|
if(isset($_GET['apprise_notify_new_species'])) {
|
||||||
exec('sudo systemctl start pushed_notifications.service');
|
$apprise_notify_new_species = 1;
|
||||||
} else {
|
} else {
|
||||||
exec('sudo systemctl stop pushed_notifications.service');
|
$apprise_notify_new_species = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logic for setting the date and time based on user inputs from the form below
|
// logic for setting the date and time based on user inputs from the form below
|
||||||
@@ -46,6 +46,7 @@ $contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id"
|
|||||||
$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_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("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents);
|
$contents = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents);
|
||||||
|
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ $contents2 = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id
|
|||||||
$contents2 = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents2);
|
$contents2 = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents2);
|
||||||
$contents2 = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents2);
|
$contents2 = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents2);
|
||||||
$contents2 = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents2);
|
$contents2 = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents2);
|
||||||
|
$contents2 = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents2);
|
||||||
$contents2 = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents2);
|
$contents2 = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents2);
|
||||||
|
|
||||||
|
|
||||||
@@ -144,8 +146,8 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
|
|||||||
<input name="apprise_notification_title" type="text" value="<?php print($config['APPRISE_NOTIFICATION_TITLE']);?>" /><br>
|
<input name="apprise_notification_title" type="text" value="<?php print($config['APPRISE_NOTIFICATION_TITLE']);?>" /><br>
|
||||||
<label for="apprise_notification_body">Notification Body (use variables $sciname, $comname, or $confidence): </label>
|
<label for="apprise_notification_body">Notification Body (use variables $sciname, $comname, or $confidence): </label>
|
||||||
<input name="apprise_notification_body" type="text" value="<?php print($config['APPRISE_NOTIFICATION_BODY']);?>" /><br>
|
<input name="apprise_notification_body" type="text" value="<?php print($config['APPRISE_NOTIFICATION_BODY']);?>" /><br>
|
||||||
<input type="checkbox" name="apprise_notify_each_species" <?php $output = shell_exec("service pushed_notifications status"); if (!strpos($output, 'dead') !== false && 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_each_species">Notify each new species</label><br>
|
<label for="apprise_notify_new_species">Notify each new species</label><br>
|
||||||
<input type="checkbox" name="apprise_notify_each_detection" <?php if($config['APPRISE_NOTIFY_EACH_DETECTION'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >
|
<input type="checkbox" name="apprise_notify_each_detection" <?php if($config['APPRISE_NOTIFY_EACH_DETECTION'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >
|
||||||
<label for="apprise_notify_each_detection">Notify each new detection</label><br><br>
|
<label for="apprise_notify_each_detection">Notify each new detection</label><br><br>
|
||||||
<h3>Bird Photos from Flickr</h3>
|
<h3>Bird Photos from Flickr</h3>
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ RTSP_STREAM=
|
|||||||
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
|
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
|
||||||
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
|
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
|
||||||
APPRISE_NOTIFY_EACH_DETECTION=0
|
APPRISE_NOTIFY_EACH_DETECTION=0
|
||||||
|
APPRISE_NOTIFY_NEW_SPECIES=0
|
||||||
|
|
||||||
#---------------------- Flickr Images API Configuration -----------------------#
|
#---------------------- Flickr Images API Configuration -----------------------#
|
||||||
|
|
||||||
|
|||||||
@@ -91,22 +91,6 @@ EOF
|
|||||||
systemctl enable extraction.service
|
systemctl enable extraction.service
|
||||||
}
|
}
|
||||||
|
|
||||||
install_pushed_notifications() {
|
|
||||||
cat << EOF > $HOME/BirdNET-Pi/templates/pushed_notifications.service
|
|
||||||
[Unit]
|
|
||||||
Description=BirdNET-Pi Pushed.co Notifications
|
|
||||||
[Service]
|
|
||||||
Restart=on-success
|
|
||||||
RestartSec=3
|
|
||||||
Type=simple
|
|
||||||
User=$USER
|
|
||||||
ExecStart=/usr/local/bin/species_notifier.sh
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
EOF
|
|
||||||
ln -sf $HOME/BirdNET-Pi/templates/pushed_notifications.service /usr/lib/systemd/system
|
|
||||||
}
|
|
||||||
|
|
||||||
create_necessary_dirs() {
|
create_necessary_dirs() {
|
||||||
echo "Creating necessary directories"
|
echo "Creating necessary directories"
|
||||||
[ -d ${EXTRACTED} ] || sudo -u ${USER} mkdir -p ${EXTRACTED}
|
[ -d ${EXTRACTED} ] || sudo -u ${USER} mkdir -p ${EXTRACTED}
|
||||||
@@ -436,7 +420,6 @@ install_services() {
|
|||||||
install_recording_service
|
install_recording_service
|
||||||
install_custom_recording_service # But does not enable
|
install_custom_recording_service # But does not enable
|
||||||
install_extraction_service
|
install_extraction_service
|
||||||
install_pushed_notifications
|
|
||||||
install_spectrogram_service
|
install_spectrogram_service
|
||||||
install_chart_viewer_service
|
install_chart_viewer_service
|
||||||
install_gotty_logs
|
install_gotty_logs
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ sudo pkill server.py
|
|||||||
sudo systemctl stop birdnet_recording.service
|
sudo systemctl stop birdnet_recording.service
|
||||||
services=(web_terminal.service
|
services=(web_terminal.service
|
||||||
spectrogram_viewer.service
|
spectrogram_viewer.service
|
||||||
pushed_notifications.service
|
|
||||||
livestream.service
|
livestream.service
|
||||||
icecast2.service
|
icecast2.service
|
||||||
extraction.service
|
extraction.service
|
||||||
@@ -22,6 +21,6 @@ sudo systemctl restart "${i}"
|
|||||||
done
|
done
|
||||||
until grep 5050 <(netstat -tulpn 2>&1);do
|
until grep 5050 <(netstat -tulpn 2>&1);do
|
||||||
sudo systemctl restart birdnet_server.service
|
sudo systemctl restart birdnet_server.service
|
||||||
sleep 30
|
sleep 45
|
||||||
done
|
done
|
||||||
sudo systemctl restart birdnet_analysis.service
|
sudo systemctl restart birdnet_analysis.service
|
||||||
|
|||||||
@@ -243,6 +243,33 @@ def sendAppriseNotifications(species,confidence):
|
|||||||
title=title,
|
title=title,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFY_NEW_SPECIES')]).split('=')[1]).split('\\')[0]) == "1":
|
||||||
|
try:
|
||||||
|
con = sqlite3.connect(userDir + '/BirdNET-Pi/scripts/birds.db')
|
||||||
|
con.row_factory = lambda cursor, row: row[0]
|
||||||
|
cur = con.cursor()
|
||||||
|
cur.execute("SELECT DISTINCT(Com_Name) FROM detections")
|
||||||
|
known_species = cur.fetchall()
|
||||||
|
sciName,comName = species.split("_")
|
||||||
|
|
||||||
|
print("\ncomName: ",comName)
|
||||||
|
print("\nknown_species: ",known_species)
|
||||||
|
if comName not in known_species:
|
||||||
|
apobj = apprise.Apprise()
|
||||||
|
config = apprise.AppriseConfig()
|
||||||
|
config.add(userDir + '/BirdNET-Pi/apprise.txt')
|
||||||
|
apobj.add(config)
|
||||||
|
|
||||||
|
apobj.notify(
|
||||||
|
body=body.replace("$sciname",species.split("_")[0]).replace("$comname",species.split("_")[1]).replace("$confidence",confidence),
|
||||||
|
title=title,
|
||||||
|
)
|
||||||
|
|
||||||
|
con.close()
|
||||||
|
except:
|
||||||
|
print("Database busy")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
def writeResultsToFile(detections, min_conf, path):
|
def writeResultsToFile(detections, min_conf, path):
|
||||||
|
|
||||||
print('WRITING RESULTS TO', path, '...', end=' ')
|
print('WRITING RESULTS TO', path, '...', end=' ')
|
||||||
|
|||||||
@@ -73,13 +73,6 @@
|
|||||||
<button type="submit" name="submit" value="sudo systemctl disable --now spectrogram_viewer.service">Disable</button>
|
<button type="submit" name="submit" value="sudo systemctl disable --now spectrogram_viewer.service">Disable</button>
|
||||||
<button type="submit" name="submit" value="sudo systemctl enable --now spectrogram_viewer.service">Enable</button>
|
<button type="submit" name="submit" value="sudo systemctl enable --now spectrogram_viewer.service">Enable</button>
|
||||||
</form>
|
</form>
|
||||||
<form action="" method="GET">
|
|
||||||
<h3>Pushed Notifications</h3>
|
|
||||||
<button type="submit" name="submit" value="sudo systemctl stop pushed_notifications.service">Stop</button>
|
|
||||||
<button type="submit" name="submit" value="sudo systemctl restart pushed_notifications.service">Restart</button>
|
|
||||||
<button type="submit" name="submit" value="sudo systemctl disable --now pushed_notifications.service">Disable</button>
|
|
||||||
<button type="submit" name="submit" value="sudo systemctl enable --now pushed_notifications.service">Enable</button>
|
|
||||||
</form>
|
|
||||||
<form action="" method="GET">
|
<form action="" method="GET">
|
||||||
<button type="submit" name="submit" value="stop_core_services.sh">Stop Core Services</button>
|
<button type="submit" name="submit" value="stop_core_services.sh">Stop Core Services</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ if ! grep APPRISE_NOTIFICATION_BODY /etc/birdnet/birdnet.conf &>/dev/null;then
|
|||||||
sudo -u$USER echo "APPRISE_NOTIFICATION_BODY=\"A \$sciname \$comname was just detected with a confidence of \$confidence\"" >> /etc/birdnet/birdnet.conf
|
sudo -u$USER echo "APPRISE_NOTIFICATION_BODY=\"A \$sciname \$comname was just detected with a confidence of \$confidence\"" >> /etc/birdnet/birdnet.conf
|
||||||
fi
|
fi
|
||||||
if ! grep APPRISE_NOTIFY_EACH_DETECTION /etc/birdnet/birdnet.conf &>/dev/null;then
|
if ! grep APPRISE_NOTIFY_EACH_DETECTION /etc/birdnet/birdnet.conf &>/dev/null;then
|
||||||
sudo -u$USER echo "APPRISE_NOTIFY_EACH_DETECTION=false" >> /etc/birdnet/birdnet.conf
|
sudo -u$USER echo "APPRISE_NOTIFY_EACH_DETECTION=0 " >> /etc/birdnet/birdnet.conf
|
||||||
|
fi
|
||||||
|
if ! grep APPRISE_NOTIFY_NEW_SPECIES /etc/birdnet/birdnet.conf &>/dev/null;then
|
||||||
|
sudo -u$USER echo "APPRISE_NOTIFY_EACH_DETECTION=0 " >> /etc/birdnet/birdnet.conf
|
||||||
fi
|
fi
|
||||||
apprise_installation_status=$(~/BirdNET-Pi/birdnet/bin/python3 -c 'import pkgutil; print("installed" if pkgutil.find_loader("apprise") else "not installed")')
|
apprise_installation_status=$(~/BirdNET-Pi/birdnet/bin/python3 -c 'import pkgutil; print("installed" if pkgutil.find_loader("apprise") else "not installed")')
|
||||||
if [[ "$apprise_installation_status" = "not installed" ]];then
|
if [[ "$apprise_installation_status" = "not installed" ]];then
|
||||||
@@ -53,3 +56,8 @@ fi
|
|||||||
if ! grep FLICKR_API_KEY /etc/birdnet/birdnet.conf &>/dev/null;then
|
if ! grep FLICKR_API_KEY /etc/birdnet/birdnet.conf &>/dev/null;then
|
||||||
sudo -u$USER echo "FLICKR_API_KEY=" >> /etc/birdnet/birdnet.conf
|
sudo -u$USER echo "FLICKR_API_KEY=" >> /etc/birdnet/birdnet.conf
|
||||||
fi
|
fi
|
||||||
|
if systemctl list-unit-files pushed_notifications.service;then
|
||||||
|
sudo systemctl disable --now pushed_notifications.service
|
||||||
|
sudo rm -f /usr/lib/systemd/system/pushed_notifications.service
|
||||||
|
sudo rm $HOME/BirdNET-Pi/templates/pushed_notifications.service
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user