diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/tracking.py | 31 |
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(':') |