diff --git a/src/trackbert/providers/postat.py b/src/trackbert/providers/postat.py index 7507f99..9416b12 100644 --- a/src/trackbert/providers/postat.py +++ b/src/trackbert/providers/postat.py @@ -2,6 +2,7 @@ from ..classes.provider import BaseProvider from ..classes.database import Event import json +import logging from dateutil.parser import parse from postat.classes.api import PostAPI @@ -13,20 +14,25 @@ class PostAT(BaseProvider): def get_status(self, tracking_number, carrier): api = PostAPI() - status = api.get_shipment_status(tracking_number) - shipment = status["data"]["einzelsendung"] - events = shipment["sendungsEvents"] - for event in events: - timestamp = event["timestamp"] - py_timestamp = parse(timestamp) - event_time = py_timestamp.strftime("%Y-%m-%d %H:%M:%S") - yield Event( - shipment_id=0, - event_time=event_time, - event_description=event["text"], - raw_event=json.dumps(event), - ) + try: + status = api.get_shipment_status(tracking_number) + shipment = status["data"]["einzelsendung"] + events = shipment["sendungsEvents"] + + for event in events: + timestamp = event["timestamp"] + py_timestamp = parse(timestamp) + event_time = py_timestamp.strftime("%Y-%m-%d %H:%M:%S") + yield Event( + shipment_id=0, + event_time=event_time, + event_description=event["text"], + raw_event=json.dumps(event), + ) + + except Exception as e: + logging.error(f"Error while fetching status: {e}") def supported_carriers(self): return [