Update notifications.py
This commit is contained in:
@@ -4,7 +4,7 @@ import socket
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import requests
|
import requests
|
||||||
import time
|
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'
|
||||||
@@ -41,12 +41,10 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
|
|||||||
body = settings_dict.get('APPRISE_NOTIFICATION_BODY')
|
body = settings_dict.get('APPRISE_NOTIFICATION_BODY')
|
||||||
sciName, comName = species.split("_")
|
sciName, comName = species.split("_")
|
||||||
|
|
||||||
print(species_last_notified)
|
|
||||||
|
|
||||||
APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES = settings_dict.get('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES')
|
APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES = settings_dict.get('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES')
|
||||||
if APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES != "0":
|
if APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES != "0":
|
||||||
if species_last_notified.get(comName) is not None:
|
if species_last_notified.get(comName) is not None:
|
||||||
if int(time.time()) - species_last_notified[comName] < int(APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES):
|
if int(timeim.time()) - species_last_notified[comName] < int(APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -104,7 +102,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
|
|||||||
.replace("$flickrimage", image_url if "{" in body else "")\
|
.replace("$flickrimage", image_url if "{" in body else "")\
|
||||||
.replace("$overlap", overlap)
|
.replace("$overlap", overlap)
|
||||||
notify(notify_body, notify_title, image_url)
|
notify(notify_body, notify_title, image_url)
|
||||||
species_last_notified[comName] = int(time.time())
|
species_last_notified[comName] = int(timeim.time())
|
||||||
|
|
||||||
APPRISE_NOTIFICATION_NEW_SPECIES_DAILY_COUNT_LIMIT = 1 # Notifies the first N per day.
|
APPRISE_NOTIFICATION_NEW_SPECIES_DAILY_COUNT_LIMIT = 1 # Notifies the first N per day.
|
||||||
if settings_dict.get('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY') == "1":
|
if settings_dict.get('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY') == "1":
|
||||||
@@ -149,7 +147,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
|
|||||||
.replace("$overlap", overlap)\
|
.replace("$overlap", overlap)\
|
||||||
+ " (first time today)"
|
+ " (first time today)"
|
||||||
notify(notify_body, notify_title, image_url)
|
notify(notify_body, notify_title, image_url)
|
||||||
species_last_notified[comName] = int(time.time())
|
species_last_notified[comName] = int(timeim.time())
|
||||||
con.close()
|
con.close()
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
@@ -197,7 +195,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
|
|||||||
.replace("$overlap", overlap)\
|
.replace("$overlap", overlap)\
|
||||||
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
|
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
|
||||||
notify(notify_body, notify_title, image_url)
|
notify(notify_body, notify_title, image_url)
|
||||||
species_last_notified[comName] = int(time.time())
|
species_last_notified[comName] = int(timeim.time())
|
||||||
con.close()
|
con.close()
|
||||||
except sqlite3.Error:
|
except sqlite3.Error:
|
||||||
print("Database busy")
|
print("Database busy")
|
||||||
|
|||||||
Reference in New Issue
Block a user