summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2013-07-09 22:01:52 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2013-07-09 22:01:52 +0200
commit6e40ac66d0597bbfe2b360a319693c84d4c46273 (patch)
tree13edb2c73b628171533b1a0f33f90848068d7b9c /modules
parent947d9143174d70b9cc10a96692c85c476ca18af1 (diff)
tracking: Added tollpost support.
Diffstat (limited to 'modules')
-rw-r--r--modules/tracking.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index 7285014..5ba09b2 100644
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -195,6 +195,37 @@ class FedexModule(TrackingModule):
results.append(TrackingResult(code, date, status, lastevent['isDelivered']))
return results
+class TollpostModule(TrackingModule):
+ name = 'tollpost'
+
+ def get_url(self, code = None):
+ url = 'http://www.tollpost.no/minside/SOPS/'
+ if code:
+ url += 'consignment/' + code
+ return code
+
+ def track(self, code):
+ code = self.splitcode(code)
+ url = 'http://www.tollpost.no/XMLServer/rest/trackandtrace'
+ data = urllib.urlencode({'q': code})
+ u = urllib2.urlopen(url, data)
+ data = u.read()
+ u.close()
+ data = json.loads(data)
+ 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 = lastevent['eventTime'].replace('T', ' ')
+ event = lastevent['eventDescription']
+ location = lastevent['location']['name']
+ status = '%s (%s)' % (event, location)
+ results.append(TrackingResult(code, date, status, delivered))
+ return results
+
def code_split(code):
if ':' in code:
return code.split(':')