summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/tracking.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index f408359..c5d292e 100644
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -242,6 +242,39 @@ class TollpostModule(TrackingModule):
results.append(TrackingResult(code, date, status.encode('utf-8'), delivered))
return results
+class PostNordModule(TrackingModule):
+ name = 'postnord'
+
+ def get_url(self, code = None):
+ url = 'http://www.postnordlogistics.no/nb/Sider/search.aspx'
+ if code:
+ url += '?' + urllib.urlencode({'k': code})
+ return url
+
+ def track(self, code):
+ code = self.splitcode(code)
+ url = 'http://logistics.postennorden.com/wsp/rest-services/ntt-service-rest/api/shipment.json'
+ url += '?' + urllib.urlencode((('id', code), ('locale', 'no'), ('consumerId', config.get(cfg_section, 'postnord_consumerid'))))
+ try:
+ u = urllib2.urlopen(url)
+ except urllib2.HTTPError as e:
+ raise PackageError(str(e))
+ data = json.load(u)
+ u.close()
+ response = data['TrackingInformationResponse']
+ results = []
+ for shipment in response['shipments']:
+ for item in shipment['items']:
+ code = item['itemId']
+ delivered = (item['status'] == 'DELIVERED')
+ lastevent = item['events'][-1]
+ date = datetime.datetime.strptime(lastevent['eventTime'], '%Y-%m-%dT%H:%M:%S')
+ event = lastevent['eventDescription']
+ location = lastevent['location']['name']
+ status = '%s (%s)' % (event, location)
+ results.append(TrackingResult(code, date, status.encode('utf-8'), delivered))
+ return results
+
def code_split(code):
if ':' in code:
return code.split(':')