Last active
September 17, 2015 08:35
-
-
Save nbr23/ee7bb9dfc204cdd26183 to your computer and use it in GitHub Desktop.
La poste tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/python3 | |
| import urllib.request | |
| import urllib.parse | |
| from bs4 import BeautifulSoup | |
| def get_colissimo_info(colissimo_id): | |
| data = urllib.parse.urlencode({'colispart': colissimo_id}) | |
| colissimo_baseurl = "http://www.colissimo.fr/portail_colissimo/suivre.do" | |
| colissimo_data = urllib.request.urlopen(colissimo_baseurl, data.encode('utf-8')) | |
| soup = BeautifulSoup(colissimo_data) | |
| dataArray = soup.find(class_='dataArray') | |
| if dataArray and dataArray.tbody and dataArray.tbody.tr: | |
| date = dataArray.tbody.tr.find(headers="Date").get_text() | |
| libelle = dataArray.tbody.tr.find(headers="Libelle").get_text() | |
| site = dataArray.tbody.tr.find(headers="site").get_text().strip() | |
| return (date, libelle, site.strip()) | |
| def get_chronopost_info(track_id): | |
| data = urllib.parse.urlencode({'listeNumeros': track_id}) | |
| track_baseurl = "http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR" | |
| track_data = urllib.request.urlopen(track_baseurl, data.encode('utf-8')) | |
| soup = BeautifulSoup(track_data) | |
| infoClass = soup.find(class_='numeroColi2') | |
| if infoClass and infoClass.get_text(): | |
| info = infoClass.get_text().split("\n") | |
| if len(info) >= 1: | |
| info = info[1].strip().split("\"") | |
| if len(info) >= 2: | |
| date = info[2] | |
| libelle = info[1] | |
| return (date, libelle) | |
| def get_colisprive_info(track_id): | |
| data = urllib.parse.urlencode({'numColis': track_id}) | |
| track_baseurl = "https://www.colisprive.com/moncolis/pages/detailColis.aspx" | |
| track_data = urllib.request.urlopen(track_baseurl, data.encode('utf-8')) | |
| soup = BeautifulSoup(track_data) | |
| dataArray = soup.find(class_='BandeauInfoColis') | |
| if dataArray and dataArray.find(class_='divStatut') and dataArray.find(class_='divStatut').find(class_='tdText'): | |
| status = dataArray.find(class_='divStatut').find(class_='tdText').get_text() | |
| return status | |
| def get_laposte_info(laposte_id): | |
| data = urllib.parse.urlencode({'id': laposte_id}) | |
| 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 | |
| and len(search_res.find_all('td')) > 3): | |
| 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 (poste_type.lower(), poste_id.strip(), poste_status.lower(), poste_location, poste_date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/python3 | |
| import sys | |
| import suivi | |
| def main(): | |
| if len(sys.argv) < 3: | |
| print("Utilisation: (-l|-c) %s <numéro d\'envoi>" % sys.argv[0]) | |
| print("\t-c: Suivi Colissimo") | |
| print("\t-l: Suivi La Poste") | |
| print("\t-k: Suivi Chronopost") | |
| print("\t-p: Suivi Colis Privé") | |
| sys.exit(1) | |
| else: | |
| if sys.argv[1] == "-l": | |
| info = suivi.get_laposte_info(sys.argv[2]) | |
| if info: | |
| poste_type, poste_id, poste_status, poste_location, poste_date = info | |
| print("Le courrier de type %s: %s est actuellement %s dans la zone %s (Mis à jour le %s)." % | |
| (poste_type, poste_id, poste_status, poste_location, poste_date)) | |
| else: | |
| print("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.") | |
| elif sys.argv[1] == "-c": | |
| info = suivi.get_colissimo_info(sys.argv[2]) | |
| if info: | |
| date, libelle, site = info | |
| print("Colis: %s. %s Dernière mise à jour le %s au site %s." % (sys.argv[2], libelle, date, site)) | |
| else: | |
| print("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.") | |
| elif sys.argv[1] == "-k": | |
| info = suivi.get_chronopost_info(sys.argv[2]) | |
| if info: | |
| date, libelle = info | |
| print("Colis: %s, Dernière mise à jour %s: %s." % (sys.argv[2], date, libelle)) | |
| else: | |
| print("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.") | |
| elif sys.argv[1] == "-p": | |
| info = suivi.get_colisprive_info(sys.argv[2]) | |
| if info: | |
| print("Colis: %s: %s." % (sys.argv[2], info)) | |
| else: | |
| print("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.") | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment