summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2017-08-31 17:33:58 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2017-08-31 17:33:58 +0200
commitc17e839b7b7e91e4720ea1192877c8b87709aa38 (patch)
treeb5c7c7fb56686d601be770bf2686d733dbdb91b1 /modules
parent7b770e6072e595bddda94d75a3739359b2f61e9e (diff)
tracking: Added Pitney Bowes (pb) module.
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/tracking.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index 957bf62..7d2ef32 100755
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -16,7 +16,9 @@ from sqlalchemy.orm import sessionmaker, relation, backref
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql import or_, and_
+import dateutil.parser
import easypost
+import requests
engine = Session = None
Base = declarative_base()
@@ -370,6 +372,34 @@ class DHLGMModule(TrackingModule, EasypostModule):
url += code
return url
+class PitneyBowes(TrackingModule):
+ name = 'pb'
+
+ def track(self, code):
+ code = self.splitcode(code)
+ url = 'https://parceltracking.pb.com/tracking/services/v1/track-packages/' + code
+ try:
+ response = requests.get(url, timeout = config.getfloat(cfg_section, 'timeout'), verify = False)
+ except Exception as e:
+ raise PackageError(str(e))
+ data = response.json()
+ date = dateutil.parser.parse('%sT%s' % (data['currentStatus']['eventDate'], data['currentStatus']['eventTime']))
+ date = date.astimezone(pytz.timezone(config.get(cfg_section, 'local_timezone')))
+ desc = data['currentStatus']['eventDescription']
+ location = data['currentStatus']['eventLocation'].get('city') or ''
+ if location and data['currentStatus']['eventLocation'].get('country'):
+ location += u', ' + data['currentStatus']['eventLocation']['country']
+ if location:
+ desc += u' (%s)' % location
+ desc = desc.encode('utf-8')
+ return [TrackingResult(code, date, desc, data['currentStatus']['packageStatus'] == 'DELIVERED')]
+
+ def get_url(self, code = None):
+ url = 'https://parceltracking.pb.com/app/#/dashboard/'
+ if code:
+ url += code
+ return url
+
def code_split(code):
if ':' in code:
return code.split(':')