linted
This commit is contained in:
@@ -2,14 +2,14 @@ import apprise
|
||||
import os
|
||||
import socket
|
||||
import sqlite3
|
||||
from sqlite3 import Error
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
|
||||
userDir = os.path.expanduser('~')
|
||||
APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
|
||||
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
||||
|
||||
|
||||
def notify(body, title):
|
||||
apobj = apprise.Apprise()
|
||||
config = apprise.AppriseConfig()
|
||||
@@ -20,6 +20,7 @@ def notify(body, title):
|
||||
title=title,
|
||||
)
|
||||
|
||||
|
||||
def sendAppriseNotifications(species, confidence, path, settings_dict, db_path=DB_PATH):
|
||||
# print(sendAppriseNotifications)
|
||||
# print(settings_dict)
|
||||
@@ -33,7 +34,7 @@ def sendAppriseNotifications(species, confidence, path, settings_dict, db_path=D
|
||||
websiteurl = settings_dict.get('BIRDNETPI_URL')
|
||||
if len(websiteurl) == 0:
|
||||
raise ValueError('Blank URL')
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
websiteurl = "http://"+socket.gethostname()+".local"
|
||||
|
||||
listenurl = websiteurl+"?filename="+path
|
||||
@@ -57,8 +58,12 @@ def sendAppriseNotifications(species, confidence, path, settings_dict, db_path=D
|
||||
numberDetections = detections[0]
|
||||
if numberDetections > 0 and numberDetections <= APPRISE_NOTIFICATION_NEW_SPECIES_DAILY_COUNT_LIMIT:
|
||||
print("send the notification")
|
||||
notify_body=body.replace("$sciname", sciName).replace("$comname", comName).replace("$confidence", confidence).replace("$listenurl", listenurl) + " (first time today)"
|
||||
notify_title=title.replace("$sciname", sciName).replace("$comname", comName).replace("$confidence", confidence).replace("$listenurl", listenurl) + " (first time today)"
|
||||
notify_body = body.replace("$sciname", sciName).replace("$comname", comName)\
|
||||
.replace("$confidence", confidence).replace("$listenurl", listenurl)\
|
||||
+ " (first time today)"
|
||||
notify_title = title.replace("$sciname", sciName).replace("$comname", comName)\
|
||||
.replace("$confidence", confidence).replace("$listenurl", listenurl)\
|
||||
+ " (first time today)"
|
||||
notify(notify_body, notify_title)
|
||||
con.close()
|
||||
except sqlite3.Error as e:
|
||||
@@ -78,8 +83,12 @@ def sendAppriseNotifications(species, confidence, path, settings_dict, db_path=D
|
||||
if len(detections):
|
||||
numberDetections = detections[0]
|
||||
if numberDetections > 0 and numberDetections <= 5:
|
||||
notify_body=body.replace("$sciname", sciName).replace("$comname", comName).replace("$confidence", confidence).replace("$listenurl", listenurl) + " (only seen "+str(int(numberDetections))+" times in last 7d)"
|
||||
notify_title=title.replace("$sciname", sciName).replace("$comname", comName).replace("$confidence", confidence).replace("$listenurl", listenurl) + " (only seen "+str(int(numberDetections))+" times in last 7d)"
|
||||
notify_body = body.replace("$sciname", sciName).replace("$comname", comName)\
|
||||
.replace("$confidence", confidence).replace("$listenurl", listenurl)\
|
||||
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
|
||||
notify_title = title.replace("$sciname", sciName).replace("$comname", comName)\
|
||||
.replace("$confidence", confidence).replace("$listenurl", listenurl)\
|
||||
+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"
|
||||
notify(notify_body, notify_title)
|
||||
con.close()
|
||||
except sqlite3.Error:
|
||||
@@ -89,5 +98,3 @@ def sendAppriseNotifications(species, confidence, path, settings_dict, db_path=D
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("notfications")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user