From c4846110c76996c84f79eb98d8b25a007cf6d5a0 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 1 Mar 2017 19:21:22 +0100 Subject: tracking: Fixed error on missing fields for UPS. Some tracking codes doesn't have the City and CountryCode fields set. --- modules/tracking.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/tracking.py b/modules/tracking.py index b59bc05..917c960 100755 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -304,7 +304,12 @@ class UpsModule(TrackingModule): continue address = activity.find('ActivityLocation/Address') - location_text = "%s, %s" % (address.find('City').text, address.find('CountryCode').text) + city = address.find('City') + cc = address.find('CountryCode') + if city is not None and cc is not None: + location_text = "%s, %s" % (city.text, cc.text) + else: + location_text = None statuscode = activity.find('Status/StatusType/Code').text event_text = activity.find('Status/StatusType/Description').text date = activity.find('Date').text @@ -312,7 +317,9 @@ class UpsModule(TrackingModule): year, month, day = int(date[0:4]), int(date[4:6]), int(date[6:8]) hour, minute, second = int(time[0:2]), int(time[2:4]), int(time[4:6]) isodate = datetime.datetime(year, month, day, hour, minute, second) - desc = "%s (%s)" % (event_text, location_text) + desc = event_text + if location_text: + desc += " (%s)" % location_text results.append(TrackingResult(code, isodate, desc, statuscode == 'D')) return results -- cgit v1.2.3