From d3028549cfb6d0f5b38f52c2731a85f1e99e5082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Fri, 23 Jun 2023 12:55:17 +0200 Subject: [PATCH] [fix] reminding notifications --- source/logic/main.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/logic/main.py b/source/logic/main.py index c024e25..52eea7f 100644 --- a/source/logic/main.py +++ b/source/logic/main.py @@ -204,7 +204,14 @@ def main(): pass else: ### get old state and examine whether the check shall be executed - rows = sqlite_query_get( + rows1 = sqlite_query_get( + database_path, + "SELECT MIN(timestamp) FROM results WHERE (check_name = :check_name) AND (notification_sent = TRUE);", + { + "check_name": check_data["name"], + } + ) + rows2 = sqlite_query_get( database_path, "SELECT timestamp, condition, notification_sent FROM results WHERE (check_name = :check_name) ORDER BY timestamp DESC LIMIT :limit;", { @@ -212,13 +219,12 @@ def main(): "limit": (check_data["threshold"] + 1), } ) - if (len(rows) <= 0): + if (len(rows2) <= 0): old_item_state = None else: - last_notification_timestamp = None count = 1 - for row in rows[1:]: - if (row[1] == rows[0][1]): + for row in rows2[1:]: + if (row[1] == rows2[0][1]): count += 1 else: break @@ -226,17 +232,11 @@ def main(): count = None else: pass - for row in rows: - if (row[2]): - last_notification_timestamp = row[0] - break - else: - pass old_item_state = { - "timestamp": rows[0][0], - "condition": condition_decode(rows[0][1]), + "timestamp": rows2[0][0], + "condition": condition_decode(rows2[0][1]), "count": count, - "last_notification_timestamp": last_notification_timestamp, + "last_notification_timestamp": rows1[0][0], } timestamp = get_current_timestamp()