Added a La Poste tracking module
This commit is contained in:
parent
9c78e9df1d
commit
7d051f7b35
@ -7,7 +7,7 @@ An extremely modulable IRC bot, built around XML configuration files!
|
|||||||
|
|
||||||
*nemubot* requires at least Python 3.3 to work.
|
*nemubot* requires at least Python 3.3 to work.
|
||||||
|
|
||||||
Some modules (like `cve` or `nextstop`) require the
|
Some modules (like `cve`, `nextstop` or `laposte`) require the
|
||||||
[BeautifulSoup module](http://www.crummy.com/software/BeautifulSoup/),
|
[BeautifulSoup module](http://www.crummy.com/software/BeautifulSoup/),
|
||||||
but the core and framework has no dependency.
|
but the core and framework has no dependency.
|
||||||
|
|
||||||
|
40
modules/laposte.py
Normal file
40
modules/laposte.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import urllib.request
|
||||||
|
import urllib.parse
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from nemubot.hooks import hook
|
||||||
|
from more import Response
|
||||||
|
|
||||||
|
nemubotversion = 3.4
|
||||||
|
|
||||||
|
def help_full():
|
||||||
|
return "Traquez vos courriers La Poste en utilisant la commande: !laposte <tracking number>\nCe service se base sur http://www.csuivi.courrier.laposte.fr/suivi/index"
|
||||||
|
|
||||||
|
|
||||||
|
@hook("cmd_hook", "laposte")
|
||||||
|
def get_tracking_info(msg):
|
||||||
|
data = urllib.parse.urlencode({'id': msg.cmds[1]})
|
||||||
|
laposte_baseurl = "http://www.part.csuivi.courrier.laposte.fr/suivi/index"
|
||||||
|
|
||||||
|
laposte_data = urllib.request.urlopen(laposte_baseurl, data.encode('utf-8'))
|
||||||
|
soup = BeautifulSoup(laposte_data)
|
||||||
|
search_res = soup.find(class_='resultat_rech_simple_table').tbody.tr
|
||||||
|
if (soup.find(class_='resultat_rech_simple_table').thead
|
||||||
|
and soup.find(class_='resultat_rech_simple_table').thead.tr):
|
||||||
|
field = search_res.find('td')
|
||||||
|
poste_id = field.get_text()
|
||||||
|
|
||||||
|
field = field.find_next('td')
|
||||||
|
poste_type = field.get_text()
|
||||||
|
|
||||||
|
field = field.find_next('td')
|
||||||
|
poste_date = field.get_text()
|
||||||
|
|
||||||
|
field = field.find_next('td')
|
||||||
|
poste_location = field.get_text()
|
||||||
|
|
||||||
|
field = field.find_next('td')
|
||||||
|
poste_status = field.get_text()
|
||||||
|
|
||||||
|
return Response("Le courrier de type \x02%s\x0F : \x02%s\x0F est actuellement \x02%s\x0F dans la zone \x02%s\x0F (Mis à jour le \x02%s\x0F)." % (poste_type.lower(), poste_id.strip(), poste_status.lower(), poste_location, poste_date), msg.channel)
|
||||||
|
return Response("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.", msg.channel)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user