add send_test_notification.py
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from utils import notifications
|
||||
from utils.helpers import DB_PATH, get_settings
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--config', help='path to config', required=True)
|
||||
parser.add_argument('--title', help='title', required=True)
|
||||
parser.add_argument('--body', help='path to body template', required=True)
|
||||
parser.add_argument('--detection', help='path to json encoded detection', required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
conf = get_settings()
|
||||
conf['APPRISE_NOTIFICATION_TITLE'] = args.title
|
||||
conf['APPRISE_NOTIFY_EACH_DETECTION'] = '1'
|
||||
conf['APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY'] = '0'
|
||||
conf['APPRISE_NOTIFY_NEW_SPECIES'] = '0'
|
||||
|
||||
notifications.APPRISE_CONFIG = args.config
|
||||
notifications.APPRISE_BODY = args.body
|
||||
|
||||
f = open(args.detection, 'r')
|
||||
d = json.loads(f.read())
|
||||
|
||||
logger = logging.getLogger()
|
||||
formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")
|
||||
handler = logging.StreamHandler(stream=sys.stdout)
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
notifications.sendAppriseNotifications(f"{d['Sci_Name']}_{d['Com_Name']}", d['Confidence'], round(d['Confidence'] * 100), d['File_Name'],
|
||||
d['Date'], d['Time'], d['Week'], d['Lat'], d['Lon'], d['Cutoff'],
|
||||
d['Sens'], d['Overlap'], dict(conf), DB_PATH)
|
||||
@@ -12,23 +12,25 @@ APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'
|
||||
APPRISE_BODY = userDir + '/BirdNET-Pi/body.txt'
|
||||
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
||||
|
||||
apobj = None
|
||||
images = {}
|
||||
species_last_notified = {}
|
||||
|
||||
|
||||
asset = apprise.AppriseAsset(
|
||||
plugin_paths=[
|
||||
userDir + "/.apprise/plugins",
|
||||
userDir + "/.config/apprise/plugins",
|
||||
]
|
||||
)
|
||||
apobj = apprise.Apprise(asset=asset)
|
||||
config = apprise.AppriseConfig()
|
||||
config.add(APPRISE_CONFIG)
|
||||
apobj.add(config)
|
||||
|
||||
|
||||
def notify(body, title, attached=""):
|
||||
global apobj
|
||||
if apobj is None:
|
||||
asset = apprise.AppriseAsset(
|
||||
plugin_paths=[
|
||||
userDir + "/.apprise/plugins",
|
||||
userDir + "/.config/apprise/plugins",
|
||||
]
|
||||
)
|
||||
apobj = apprise.Apprise(asset=asset)
|
||||
config = apprise.AppriseConfig()
|
||||
config.add(APPRISE_CONFIG)
|
||||
apobj.add(config)
|
||||
|
||||
if attached != "":
|
||||
apobj.notify(
|
||||
body=body,
|
||||
@@ -48,20 +50,20 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,
|
||||
def render_template(template, reason=""):
|
||||
ret = template.replace("$sciname", sciName) \
|
||||
.replace("$comname", comName) \
|
||||
.replace("$confidencepct", confidencepct) \
|
||||
.replace("$confidence", confidence) \
|
||||
.replace("$confidencepct", str(confidencepct)) \
|
||||
.replace("$confidence", str(confidence)) \
|
||||
.replace("$listenurl", listenurl) \
|
||||
.replace("$friendlyurl", friendlyurl) \
|
||||
.replace("$date", date) \
|
||||
.replace("$time", time) \
|
||||
.replace("$week", week) \
|
||||
.replace("$latitude", latitude) \
|
||||
.replace("$longitude", longitude) \
|
||||
.replace("$cutoff", cutoff) \
|
||||
.replace("$sens", sens) \
|
||||
.replace("$date", str(date)) \
|
||||
.replace("$time", str(time)) \
|
||||
.replace("$week", str(week)) \
|
||||
.replace("$latitude", str(latitude)) \
|
||||
.replace("$longitude", str(longitude)) \
|
||||
.replace("$cutoff", str(cutoff)) \
|
||||
.replace("$sens", str(sens)) \
|
||||
.replace("$flickrimage", image_url if "{" in body else "") \
|
||||
.replace("$image", image_url if "{" in body else "") \
|
||||
.replace("$overlap", overlap) \
|
||||
.replace("$overlap", str(overlap)) \
|
||||
.replace("$reason", reason)
|
||||
return ret
|
||||
# print(sendAppriseNotifications)
|
||||
|
||||
Reference in New Issue
Block a user