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