Merge pull request #520 from pf56/fixed-dhl

Fixed parcel tracking for DHL
This commit is contained in:
enkore 2017-01-11 12:36:45 +01:00 committed by GitHub
commit 50bbf762e4

View File

@ -65,27 +65,18 @@ class DHL(TrackerAPI):
self.idcode = idcode self.idcode = idcode
self.url = self.URL.format(idcode=self.idcode) self.url = self.URL.format(idcode=self.idcode)
def error(self, page):
result = ''.join(page.xpath('//div[@class="col col-lg-12"]/h2/text()'))
if self.idcode in result:
return False
return True
def get_progress(self, page): def get_progress(self, page):
elements = page.xpath('//tr[@class="mm_mailing_process "]/td/ul/li') elements = page.xpath('//div[contains(@class, "package-status")]/div/ol/li')
progress = "n/a"
status = 0
for i, element in enumerate(elements, 1): for i, element in enumerate(elements, 1):
picture_link = ''.join(element.xpath('./img/@src')).lower() picture_link = ''.join(element.xpath('./img/@src')).lower()
if 'active' in picture_link: if picture_link.endswith("_on.svg"):
status = ''.join(element.xpath('./img/@alt')) status = ''.join(element.xpath('./img/@alt'))
progress = '%i' % (i / len(elements) * 100) progress = '%i' % (i / len(elements) * 100)
elif 'default' in picture_link:
break
return progress, status return progress, status
def status(self): def status(self):
@ -93,10 +84,6 @@ class DHL(TrackerAPI):
with urlopen(self.url) as page: with urlopen(self.url) as page:
page = lxml.html.fromstring(page.read()) page = lxml.html.fromstring(page.read())
if not self.error(page):
ret["progress"] = ret["status"] = "n/a"
else:
progress, status = self.get_progress(page) progress, status = self.get_progress(page)
ret["progress"] = progress ret["progress"] = progress
ret["status"] = status ret["status"] = status