Skip to content

Instantly share code, notes, and snippets.

@ork
Last active January 8, 2022 17:29
Show Gist options
  • Save ork/031f94604718769b20d8 to your computer and use it in GitHub Desktop.
Save ork/031f94604718769b20d8 to your computer and use it in GitHub Desktop.
Colissymo
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
from datetime import datetime
class Colissymo(object):
__UA_STRING = 'Mozilla/5.0 (Colissymo)'
__ROOT_URI = 'http://www.colissimo.fr/portail_colissimo/'
def __init__(self):
self.session = requests.Session()
self.session.headers.update({'User-Agent': self.__UA_STRING})
def track_package(self, identifier=None):
if identifier is None:
return None
req = self.session.get(self.__ROOT_URI + 'suivre.do',
params={'colispart': identifier})
soup = BeautifulSoup(req.text)
table = soup.find('table', attrs={'class': 'dataArray'})
headings = [th.get_text() for th in table.find('tr').find_all('td')]
ret = []
for row in table.find_all('tr')[1:]:
dat, lab, loc = (c.get_text().strip() for c in row.find_all('td'))
ret.append(dict(zip(
headings,
(datetime.strptime(dat, '%d/%m/%Y'), lab, loc))))
return reversed(ret)
if __name__ == '__main__':
import sys
from pprint import pprint
c = Colissymo()
pprint(list(c.track_package(sys.argv[1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment