From ebcb3ef6aa393093b67adec130d6be131731eb59 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 23 Aug 2023 12:09:47 +0200 Subject: [PATCH] Fix latest known event logging - The code now checks if there is a latest known event before logging it. If there is no latest known event, it logs "No known events for {tracking_number}". - The logging for the latest known event now includes the event description and name. - This change improves the logging output for the latest known event, making it more informative. --- trackbert.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trackbert.py b/trackbert.py index 4f0b490..94f3521 100644 --- a/trackbert.py +++ b/trackbert.py @@ -232,7 +232,11 @@ def start_loop(db: sqlite3.Connection, api: KeyDelivery) -> Never: events = sorted(all_events["data"]["items"], key=lambda x: x["time"], reverse=True) - logging.debug(f"Latest known event for {tracking_number}: {latest_known_event[3]} - {latest_known_event[2]}") + if latest_known_event: + logging.debug(f"Latest known event for {tracking_number}: {latest_known_event[3]} - {latest_known_event[2]}") + else: + logging.debug(f"No known events for {tracking_number}") + logging.debug(f"Latest upstream event for {tracking_number}: {events[0]['context']} - {events[0]['time']}") latest = True