summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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(':')