From 52b3bfa945520d82102746814930c4b36541eaba Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 2 Jul 2017 19:08:01 +0200 Subject: [PATCH] suivi: add postnl tracking --- modules/suivi.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/suivi.py b/modules/suivi.py index 19e4d20..79910d4 100644 --- a/modules/suivi.py +++ b/modules/suivi.py @@ -108,6 +108,30 @@ def get_laposte_info(laposte_id): poste_location, poste_date) +def get_postnl_info(postnl_id): + data = urllib.parse.urlencode({'barcodes': postnl_id}) + postnl_baseurl = "http://www.postnl.post/details/" + + postnl_data = urllib.request.urlopen(postnl_baseurl, + data.encode('utf-8')) + soup = BeautifulSoup(postnl_data) + if (soup.find(id='datatables') + and soup.find(id='datatables').tbody + and soup.find(id='datatables').tbody.tr): + search_res = soup.find(id='datatables').tbody.tr + if len(search_res.find_all('td')) >= 3: + field = field.find_next('td') + post_date = field.get_text() + + field = field.find_next('td') + post_status = field.get_text() + + field = field.find_next('td') + post_destination = field.get_text() + + return (post_status.lower(), post_destination, post_date) + + # TRACKING HANDLERS ################################################### def handle_tnt(tracknum): @@ -133,6 +157,15 @@ def handle_laposte(tracknum): poste_location, poste_date)) +def handle_postnl(tracknum): + info = get_postnl_info(tracknum) + if info: + post_status, post_destination, post_date = info + return ("PostNL \x02%s\x0F est actuellement " + "\x02%s\x0F vers le pays \x02%s\x0F (Mis à jour le \x02%s\x0F" + ")." % (tracknum, post_status, post_destination, post_date)) + + def handle_colissimo(tracknum): info = get_colissimo_info(tracknum) if info: @@ -158,6 +191,7 @@ def handle_coliprive(tracknum): TRACKING_HANDLERS = { 'laposte': handle_laposte, + 'postnl': handle_postnl, 'colissimo': handle_colissimo, 'chronopost': handle_chronopost, 'coliprive': handle_coliprive,