From 4011141108f5992f8231208ba9f42d52da2e4d0e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 30 Jul 2015 15:27:48 +0200 Subject: tracking: Fixed errors on missing fields in PostNord. --- modules/tracking.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/tracking.py b/modules/tracking.py index 1a09de4..1e74001 100755 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -231,11 +231,13 @@ class PostNordModule(TrackingModule): for shipment in response['shipments']: for item in shipment['items']: code = item['itemId'] - delivered = (item['status'] == 'DELIVERED') + delivered = (item.get('status') == 'DELIVERED') lastevent = item['events'][-1] date = datetime.datetime.strptime(lastevent['eventTime'], '%Y-%m-%dT%H:%M:%S') event = lastevent['eventDescription'] - location = lastevent['location'].get('name') or lastevent['location'].get('city') + location = lastevent.get('location') + if location: + location = lastevent['location'].get('name') or lastevent['location'].get('city') if location: status = '%s (%s)' % (event, location) else: -- cgit v1.2.3