Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def get_info(self, _id):
        shipments = self.doc["shipments"]
        if not shipments:
            raise ParcelNotFound("No such ID: %s" % _id)
        shipment = shipments[0]
        result_id = shipment["trackingCode"]
        if result_id != _id:
            raise ParcelNotFound("ID mismatch: expecting %s, got %s" % (_id, result_id))

        p = Parcel(_id)
        if shipment["estimatedDeliveryTime"]:
            p.arrival = parse_date(shipment["estimatedDeliveryTime"], ignoretz=True)
        events = shipment["events"]
        p.history = [self.build_event(i, data) for i, data in enumerate(events)]
        most_recent = p.history[0]
        p.status, p.info = self.guess_status(p.history)
        p.info = most_recent.activity
        return p
Exemplo n.º 4
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
Exemplo n.º 5
0
    def get_info(self, _id):
        shipments = self.doc["shipments"]
        if not shipments:
            raise ParcelNotFound("No such ID: %s" % _id)
        shipment = shipments[0]
        result_id = shipment["trackingCode"]
        if result_id != _id:
            raise ParcelNotFound("ID mismatch: expecting %s, got %s" %
                                 (_id, result_id))

        p = Parcel(_id)
        if shipment["estimatedDeliveryTime"]:
            p.arrival = parse_date(shipment["estimatedDeliveryTime"],
                                   ignoretz=True)
        events = shipment["events"]
        p.history = [
            self.build_event(i, data) for i, data in enumerate(events)
        ]
        most_recent = p.history[0]
        p.status, p.info = self.guess_status(p.history)
        p.info = most_recent.activity
        return p
Exemplo n.º 6
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
Exemplo n.º 7
0
    def get_parcel_tracking(self, _id):
        """
        Get information about a parcel.

        :param _id: _id of the parcel
        :type _id: :class:`str`
        :rtype: :class:`Parcel`
        :raises: :class:`ParcelNotFound`
        """
        # Tracking number format:
        # - 2 chars: optional merchant identifier (eg, AM for Amazon, 85 for cdiscount, ...)
        # - 10 digits: shipment tracking number
        # - 2 digits: optional suffix, seems to always be "01" when present but is never sent to the API
        #
        # Many merchants seem to give only the 10 digits tracking number so the user needs to
        # manually select the merchant from a list in that case.

        merchant = None
        code = None

        _id = _id.strip().upper()

        if len(_id) == 10:
            code = _id
        elif len(_id) in (12, 14):
            merchant = _id[:2]
            code = _id[2:12]
        else:
            raise ParcelNotFound(
                "Tracking number must be 10, 12 or 14 characters long.")

        merchant = merchant or self.config['merchant'].get()

        if not merchant:
            # No merchant info in the tracking number
            # we have to ask the user to select it
            merchants = self.browser.get_merchants()
            raise BrowserQuestion(
                Value(
                    'merchant',
                    label='Merchant prefix (prepend to tracking number): ',
                    tiny=False,
                    choices=merchants,
                ))

        self.config['merchant'].set(None)
        name = self.config['last_name'].get()[:4].ljust(4).upper()

        events = list(self.browser.iter_events(merchant, code, name))

        parcel = Parcel(merchant + code)
        parcel.arrival = NotAvailable

        # This is what the legacy tracking website used to show
        # when there are no events yet
        parcel.info = "Votre commande est en cours d'acheminement dans notre réseau."

        parcel.history = events
        parcel.status = Parcel.STATUS_IN_TRANSIT

        if not events:
            parcel.status = Parcel.STATUS_PLANNED
            return parcel

        parcel.info = events[0].activity

        arrived_event = next(
            (event for event in events
             if "Votre colis est disponible" in event.activity), None)

        if arrived_event:
            parcel.status = Parcel.STATUS_ARRIVED
            parcel.arrival = arrived_event.date

        return parcel
Exemplo n.º 8
0
    def get_parcel_tracking(self, _id):
        """
        Get information about a parcel.

        :param _id: _id of the parcel
        :type _id: :class:`str`
        :rtype: :class:`Parcel`
        :raises: :class:`ParcelNotFound`
        """
        # Tracking number format:
        # - 2 chars: optional merchant identifier (eg, AM for Amazon, 85 for cdiscount, ...)
        # - 10 digits: shipment tracking number
        # - 2 digits: optional suffix, seems to always be "01" when present but is never sent to the API
        #
        # Many merchants seem to give only the 10 digits tracking number so the user needs to
        # manually select the merchant from a list in that case.

        merchant = None
        code = None

        _id = _id.strip().upper()

        if len(_id) == 10:
            code = _id
        elif len(_id) in (12, 14):
            merchant = _id[:2]
            code = _id[2:12]
        else:
            raise ParcelNotFound(
                "Tracking number must be 10, 12 or 14 characters long."
            )

        merchant = merchant or self.config['merchant'].get()

        if not merchant:
            # No merchant info in the tracking number
            # we have to ask the user to select it
            merchants = self.browser.get_merchants()
            raise BrowserQuestion(Value(
                'merchant', label='Merchant prefix (prepend to tracking number): ', tiny=False,
                choices=merchants,
            ))

        self.config['merchant'].set(None)
        name = self.config['last_name'].get()[:4].ljust(4).upper()

        events = list(self.browser.iter_events(merchant, code, name))

        parcel = Parcel(merchant + code)
        parcel.arrival = NotAvailable

        # This is what the legacy tracking website used to show
        # when there are no events yet
        parcel.info = "Votre commande est en cours d'acheminement dans notre réseau."

        parcel.history = events
        parcel.status = Parcel.STATUS_IN_TRANSIT

        if not events:
            parcel.status = Parcel.STATUS_PLANNED
            return parcel

        parcel.info = events[0].activity

        arrived_event = next((event for event in events
                             if "Votre colis est disponible" in event.activity),
                             None)

        if arrived_event:
            parcel.status = Parcel.STATUS_ARRIVED
            parcel.arrival = arrived_event.date

        return parcel