Example #1
0
    def get_info(self, id):
        if len(self.document.xpath('//libelle[@nom="MSG_AUCUN_EVT"]')) > 0:
            return None

        p = Parcel(id)
        p.arrival = NotAvailable
        p.history = []

        for i, tr in enumerate(self.document.xpath('//table[@class="tabListeEnvois"]//tr')):
            tds = tr.findall('td')
            if len(tds) < 3:
                continue

            ev = Event(i)
            ev.location = unicode(tds[1].text) if tds[1].text else None
            ev.activity = unicode(tds[1].find('br').tail)
            if tds[-1].text is not None:
                ev.activity += ', ' + self.parser.tocleanstring(tds[-1])
            date = re.sub('[a-z]+', '', self.parser.tocleanstring(tds[0])).strip()
            date = re.sub('(\d+)/(\d+)/(\d+)', r'\3-\2-\1', date)
            ev.date = parse_date(date)
            p.history.append(ev)

        p.info = ' '.join([t.strip() for t in self.document.xpath('//div[@class="numeroColi2"]')[0].itertext()][1:])
        if u'Livraison effectuée' in p.history[0].activity:
            p.status = p.STATUS_ARRIVED

        return p
Example #2
0
 def build_event(self, e):
     index = e[u'counter']
     event = Event(index)
     event.date = parse_date(e[u'date'] + " " + e.get(u'time', ''), dayfirst=True, fuzzy=True)
     event.location = e.get(u'location', '')
     event.activity = e[u'description']
     return event
Example #3
0
 def build_event(self, index, data):
     event = Event(index)
     date = "%s %s" % (data["date"], data["time"])
     event.date = parse_date(date, dayfirst=False)
     event.location = unicode(data["city"])
     event.activity = unicode(", ".join([_["label"] for _ in data["contents"]]))
     return event
Example #4
0
 def build_event(self, e):
     index = e[u'counter']
     event = Event(index)
     event.date = parse_date(e[u'date'] + " " + e.get(u'time', ''), dayfirst=True, fuzzy=True)
     event.location = e.get(u'location', '')
     event.activity = e[u'description']
     return event
Example #5
0
    def get_info(self, id):
        if len(self.document.xpath('//libelle[@nom="MSG_AUCUN_EVT"]')) > 0:
            return None

        p = Parcel(id)
        p.arrival = NotAvailable
        p.history = []

        for i, tr in enumerate(
                self.document.xpath('//table[@class="tabListeEnvois"]//tr')):
            tds = tr.findall('td')
            if len(tds) < 3:
                continue

            ev = Event(i)
            ev.location = unicode(tds[1].text) if tds[1].text else None
            ev.activity = unicode(tds[1].find('br').tail)
            if tds[-1].text is not None:
                ev.activity += ', ' + self.parser.tocleanstring(tds[-1])
            date = re.sub('[a-z]+', '',
                          self.parser.tocleanstring(tds[0])).strip()
            date = re.sub('(\d+)/(\d+)/(\d+)', r'\3-\2-\1', date)
            ev.date = parse_date(date)
            p.history.append(ev)

        p.info = ' '.join([
            t.strip() for t in self.document.xpath(
                '//div[@class="numeroColi2"]')[0].itertext()
        ][1:])
        if u'Livraison effectuée' in p.history[0].activity:
            p.status = p.STATUS_ARRIVED

        return p
Example #6
0
 def build_event(self, index, data):
     event = Event(index)
     date = "%s %s" % (data["date"], data["time"])
     event.date = parse_date(date, dayfirst=False)
     event.location = ", ".join(
         [unicode(data["address"][field]) for field in ["city", "countryName"] if data["address"][field]])
     event.activity = unicode(data["evtDscr"])
     return event
Example #7
0
 def build_event(self, index, data):
     event = Event(index)
     date = "%s %s" % (data["date"], data["time"])
     event.date = parse_date(date, dayfirst=False)
     event.location = ", ".join(
         [unicode(data["address"][field]) for field in ["city", "countryName"] if data["address"][field]])
     event.activity = unicode(data["evtDscr"])
     return event
Example #8
0
 def build_event(self, index, div):
     event = Event(index)
     event.activity = unicode(div.xpath('div[@class="shipment-event-table-header"]')[0].text)
     event.date = parse_date(div.xpath('.//span[@class="shipment-event-table-label" and text()="Registration:"]/'
                                       'following-sibling::span')[0].text)
     event.location = unicode(div.xpath('.//span[@class="shipment-event-table-label" and text()="Location:"]/'
                                        'following-sibling::span')[0].text)
     return event
Example #9
0
    def iter_events(self, merchant, code, name):
        data = dict(
            codeEnseigne=merchant,
            nomClient=name,
            typeRecherche='EXP',
            valeur=code
        )
        # Ref: https://www.relaiscolis.com/js/lib/suivi.js
        req = self.open('/suivi-de-colis/index/tracking/', data=data)
        resp = None
        try:
            resp = req.json()
            if resp and 'error' in resp:
                raise ParcelNotFound(resp['error']['msg'])
        except (ValueError, KeyError):
            self.raise_for_status(req)
            raise
        else:
            self.raise_for_status(req)

        def ensure_list(data):
            if isinstance(data, list):
                return data
            return [data]

        parcel_data = ensure_list(resp['Colis']['Colis'])[-1]
        events_data = ensure_list(parcel_data['ListEvenements'].get('Evenement', []))

        final_location = None
        try:
            relay = resp['Relais']['Relais']
            name = relay['Nom'].strip()
            city = relay['Commune'].strip()
            final_location = ' '.join((name, city))
        except KeyError:
            pass

        for event_data in events_data:
            event = Event()
            event.date = parse_date(event_data['Date'].strip())
            event.activity = event_data['Libelle'].strip()

            if final_location and (
                    "Votre colis est disponible" in event.activity):
                event.location = final_location
            yield event
Example #10
0
    def iter_events(self, merchant, code, name):
        data = dict(codeEnseigne=merchant,
                    nomClient=name,
                    typeRecherche='EXP',
                    valeur=code)
        # Ref: https://www.relaiscolis.com/js/lib/suivi.js
        req = self.open('/suivi-de-colis/index/tracking/', data=data)
        resp = None
        try:
            resp = req.json()
            if resp and 'error' in resp:
                raise ParcelNotFound(resp['error']['msg'])
        except (ValueError, KeyError):
            self.raise_for_status(req)
            raise
        else:
            self.raise_for_status(req)

        def ensure_list(data):
            if isinstance(data, list):
                return data
            return [data]

        parcel_data = ensure_list(resp['Colis']['Colis'])[-1]
        events_data = ensure_list(parcel_data['ListEvenements'].get(
            'Evenement', []))

        final_location = None
        try:
            relay = resp['Relais']['Relais']
            name = relay['Nom'].strip()
            city = relay['Commune'].strip()
            final_location = ' '.join((name, city))
        except KeyError:
            pass

        for event_data in events_data:
            event = Event()
            event.date = parse_date(event_data['Date'].strip())
            event.activity = event_data['Libelle'].strip()

            if final_location and ("Votre colis est disponible"
                                   in event.activity):
                event.location = final_location
            yield event
Example #11
0
    def get_info(self, _id):
        p = Parcel(_id)

        statustr = self.doc.xpath('//tr[@class="bandeauText"]')[0]
        status = statustr.xpath('td')[1].text

        p.info = status
        p.status = p.STATUS_UNKNOWN

        p.history = []
        for i, tr in enumerate(self.doc.xpath('//table[@class="tableHistoriqueColis"]//tr[@class="bandeauText"]')):
            tds = tr.findall('td')
            try:
                if tds[0].attrib['class'] != "tdText":
                    continue
            except:
                continue

            ev = Event(i)
            ev.location = None
            ev.activity = tds[1].text
            if u"Votre colis a été expédié par votre webmarchand" in ev.activity:
                update_status(p, p.STATUS_PLANNED)
            elif u"Votre colis est pris en charge par Colis Privé" in ev.activity:
                update_status(p, p.STATUS_IN_TRANSIT)
            elif u"Votre colis est arrivé sur notre agence régionale" in ev.activity:
                update_status(p, p.STATUS_IN_TRANSIT)
            elif u"Votre colis est en cours de livraison" in ev.activity:
                update_status(p, p.STATUS_IN_TRANSIT)
            elif u"Votre colis a été livré" in ev.activity:
                update_status(p, p.STATUS_ARRIVED)
            ev.date = date(*reversed([int(x) for x in tds[0].text.split('/')]))
            p.history.append(ev)

        try:
            datelivre = self.doc.xpath('//div[@class="NoInstNoRecla"]')
            clean = datelivre[0].text
            if "Votre colis a déja été livré" in clean:
                p.status = p.STATUS_ARRIVED
        except:
            pass
        return p
Example #12
0
    def get_parcel_tracking(self, _id):
        data = self.browser.get_tracking_info(_id)
        p = Parcel(_id)
        label = data['message']
        if data['error']:
            p.info = label
            return p
        p.info = label
        # TODO, need to know the delivery message
        if u"remis au gardien ou" in label or u"Votre colis est livré" in label:
            p.status = p.STATUS_ARRIVED
        elif u"pas encore pris en charge par La Poste" in label:
            p.status = p.STATUS_PLANNED
        else:
            p.status = p.STATUS_IN_TRANSIT

        ev = Event(0)
        ev.activity = label
        ev.date = date(*reversed([int(x) for x in data['date'].split("/")]))
        p.history = [ev]

        return p
Example #13
0
    def get_info(self, id):
        if len(self.parser.tocleanstring(self.document.xpath('//p[@class="error"]')[0])) > 0:
            return None

        p = Parcel(id)
        for dl in self.document.xpath('//dl'):
            dt = dl.find('dt')
            dd = dl.find('dd')
            if dt is None or dd is None:
                continue
            label = self.parser.tocleanstring(dt)
            if label == 'Scheduled Delivery:':
                p.status = p.STATUS_IN_TRANSIT
            elif label == u'Delivered On:':
                p.status = p.STATUS_ARRIVED
            else:
                continue

            m = re.search('(\d+/\d+/\d+)', dd.text)
            if m:
                p.arrival = parse_date(m.group(1))

        p.history = []
        for i, tr in enumerate(self.document.xpath('//table[@class="dataTable"]//tr')):
            tds = tr.findall('td')
            if len(tds) < 4:
                continue

            ev = Event(i)
            ev.location = self.parser.tocleanstring(tds[0])
            ev.activity = self.parser.tocleanstring(tds[-1])
            ev.date = parse_date('%s %s' % (tds[1].text, tds[2].text))
            p.history.append(ev)

        p.info = self.document.xpath('//a[@id="tt_spStatus"]')[0].text.strip()

        return p
Example #14
0
    def get_parcel_tracking(self, _id):
        # 13 is the magic length of colissimo tracking ids
        if len(_id) != 13:
            raise ParcelNotFound(u"Colissimo ID's must have 13 print character")
        data = self.browser.get_tracking_info(_id)
        p = Parcel(_id)
        label = data["message"]
        if data["error"]:
            raise ParcelNotFound(label + u" (id = %s@%s)" % (_id, self.name))
        p.info = label
        # TODO, need to know the delivery message
        if u"remis au gardien ou" in label or u"Votre colis est livré" in label:
            p.status = p.STATUS_ARRIVED
        elif u"pas encore pris en charge par La Poste" in label:
            p.status = p.STATUS_PLANNED
        else:
            p.status = p.STATUS_IN_TRANSIT

        ev = Event(0)
        ev.activity = label
        ev.date = date(*reversed([int(x) for x in data["date"].split("/")]))
        p.history = [ev]

        return p
Example #15
0
 def build_event(self, index, data):
     event = Event(index)
     event.activity = data["description"]["en"]
     event.date = parse_date(data["timestamp"], ignoretz=True)
     event.location = data["locationName"]
     return event
Example #16
0
 def build_event(self, index, tr):
     event = Event(index)
     event.date = parse_date(tr.xpath('./td[1]')[0].text.strip(), dayfirst=True, fuzzy=True)
     event.location = unicode(tr.xpath('./td[2]')[0].text.strip())
     event.activity = unicode(tr.xpath('./td[3]')[0].text.strip())
     return event