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'
|
APPRISE_BODY = userDir + '/BirdNET-Pi/body.txt'
|
||||||
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'
|
||||||
|
|
||||||
|
apobj = None
|
||||||
images = {}
|
images = {}
|
||||||
species_last_notified = {}
|
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=""):
|
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 != "":
|
if attached != "":
|
||||||
apobj.notify(
|
apobj.notify(
|
||||||
body=body,
|
body=body,
|
||||||
@@ -48,20 +50,20 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,
|
|||||||
def render_template(template, reason=""):
|
def render_template(template, reason=""):
|
||||||
ret = template.replace("$sciname", sciName) \
|
ret = template.replace("$sciname", sciName) \
|
||||||
.replace("$comname", comName) \
|
.replace("$comname", comName) \
|
||||||
.replace("$confidencepct", confidencepct) \
|
.replace("$confidencepct", str(confidencepct)) \
|
||||||
.replace("$confidence", confidence) \
|
.replace("$confidence", str(confidence)) \
|
||||||
.replace("$listenurl", listenurl) \
|
.replace("$listenurl", listenurl) \
|
||||||
.replace("$friendlyurl", friendlyurl) \
|
.replace("$friendlyurl", friendlyurl) \
|
||||||
.replace("$date", date) \
|
.replace("$date", str(date)) \
|
||||||
.replace("$time", time) \
|
.replace("$time", str(time)) \
|
||||||
.replace("$week", week) \
|
.replace("$week", str(week)) \
|
||||||
.replace("$latitude", latitude) \
|
.replace("$latitude", str(latitude)) \
|
||||||
.replace("$longitude", longitude) \
|
.replace("$longitude", str(longitude)) \
|
||||||
.replace("$cutoff", cutoff) \
|
.replace("$cutoff", str(cutoff)) \
|
||||||
.replace("$sens", sens) \
|
.replace("$sens", str(sens)) \
|
||||||
.replace("$flickrimage", image_url if "{" in body else "") \
|
.replace("$flickrimage", image_url if "{" in body else "") \
|
||||||
.replace("$image", image_url if "{" in body else "") \
|
.replace("$image", image_url if "{" in body else "") \
|
||||||
.replace("$overlap", overlap) \
|
.replace("$overlap", str(overlap)) \
|
||||||
.replace("$reason", reason)
|
.replace("$reason", reason)
|
||||||
return ret
|
return ret
|
||||||
# print(sendAppriseNotifications)
|
# print(sendAppriseNotifications)
|
||||||
|
|||||||
Reference in New Issue
Block a user