summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2017-03-01 19:21:22 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2017-03-01 19:21:22 +0100
commitc4846110c76996c84f79eb98d8b25a007cf6d5a0 (patch)
treece41a8fa20fe52b60671223ee465ac866a159a4f
parentbf75c7a25ff1e7175d235bc5c330aada42fbba6b (diff)
tracking: Fixed error on missing fields for UPS.
Some tracking codes doesn't have the City and CountryCode fields set.
-rwxr-xr-xmodules/tracking.py11
1 files changed, 9 insertions, 2 deletions
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