fix: enable sending test notifications with an empty db

This commit is contained in:
frederik
2025-10-19 11:22:09 +02:00
parent 771855812f
commit d154b5f6f1
2 changed files with 15 additions and 26 deletions
+14 -10
View File
@@ -1,17 +1,17 @@
import argparse
import json
import datetime
import logging
import sys
from utils import notifications
from utils.helpers import DB_PATH, get_settings
from utils.helpers import get_settings
from utils.db import get_latest
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()
@@ -23,9 +23,6 @@ if __name__ == "__main__":
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)
@@ -33,7 +30,14 @@ if __name__ == "__main__":
logger.addHandler(handler)
logger.setLevel(logging.INFO)
notifications.sendAppriseNotifications(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)
d = get_latest()
if not d:
now = datetime.datetime.now()
d = {'Sci_Name': 'Aptenodytes patagonicus', 'Com_Name': 'King Penguin', 'Confidence': 0.84, 'File_Name': 'this_is_not_a_file.mp3',
'Date': now.strftime('%Y-%m-%d'), 'Time': now.strftime("%H:%M:%S"), 'Week': now.isocalendar()[1],
'Lat': conf.getfloat('LATITUDE'), 'Lon': conf.getfloat('LONGITUDE'), 'Cutoff': conf.getfloat('CONFIDENCE'),
'Sens': conf.getfloat('SENSITIVITY'), 'Overlap': conf.getfloat('OVERLAP')}
notifications.sendAppriseNotifications(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))