[suivi] Fix TNT tracking
This commit is contained in:
parent
91b550754f
commit
f15ebd7c02
|
@ -16,12 +16,19 @@ from more import Response
|
|||
# POSTAGE SERVICE PARSERS ############################################
|
||||
|
||||
def get_tnt_info(track_id):
|
||||
values = []
|
||||
data = getURLContent('www.tnt.fr/public/suivi_colis/recherche/'
|
||||
'visubontransport.do?bonTransport=%s' % track_id)
|
||||
soup = BeautifulSoup(data)
|
||||
status = soup.find('p', class_='suivi-title-selected')
|
||||
if status:
|
||||
return status.get_text()
|
||||
status_list = soup.find('div', class_='result__content')
|
||||
if not status_list:
|
||||
return None
|
||||
last_status = status_list.find('div', class_='roster')
|
||||
if last_status:
|
||||
for info in last_status.find_all('div', class_='roster__item'):
|
||||
values.append(info.get_text().strip())
|
||||
if len(values) == 3:
|
||||
return (values[0], values[1], values[2])
|
||||
|
||||
|
||||
def get_colissimo_info(colissimo_id):
|
||||
|
@ -106,8 +113,14 @@ def get_laposte_info(laposte_id):
|
|||
def handle_tnt(tracknum):
|
||||
info = get_tnt_info(tracknum)
|
||||
if info:
|
||||
status, date, place = info
|
||||
placestr = ''
|
||||
if place:
|
||||
placestr = ' à \x02{place}\x0f'
|
||||
return ('Le colis \x02{trackid}\x0f a actuellement le status: '
|
||||
'\x02{status}\x0F'.format(trackid=tracknum, status=info))
|
||||
'\x02{status}\x0F mis à jour le \x02{date}\x0f{place}.'
|
||||
.format(trackid=tracknum, status=status,
|
||||
date=re.sub(r'\s+', ' ', date), place=placestr))
|
||||
|
||||
|
||||
def handle_laposte(tracknum):
|
||||
|
|
|
@ -92,7 +92,8 @@ def parselisten(msg):
|
|||
def parseresponse(msg):
|
||||
global LAST_URLS
|
||||
if hasattr(msg, "text") and isinstance(msg.text, str):
|
||||
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?(?:[^ :/]+:[0-9]+)?[^ :]+)", msg.text)
|
||||
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?(?:[^ :/]+:[0-9]+)?[^ :]+)",
|
||||
msg.text)
|
||||
for url in urls:
|
||||
o = urlparse(web._getNormalizedURL(url), "http")
|
||||
|
||||
|
@ -130,7 +131,7 @@ def cmd_reduceurl(msg):
|
|||
raise IMException("I have no more URL to reduce.")
|
||||
|
||||
if len(msg.args) > 4:
|
||||
raise IMException("I cannot reduce that maby URLs at once.")
|
||||
raise IMException("I cannot reduce that many URLs at once.")
|
||||
else:
|
||||
minify += msg.args
|
||||
|
||||
|
|
Loading…
Reference in New Issue