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.
This commit is contained in:
Kumi 2023-08-23 12:09:47 +02:00
parent d09daaa0cc
commit ebcb3ef6aa
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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) 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']}") logging.debug(f"Latest upstream event for {tracking_number}: {events[0]['context']} - {events[0]['time']}")
latest = True latest = True