Example #1
0
    def get_encomenda_info(self, numero):
        data = {
            'acao': 'track',
            'objetos': numero,
            'btnPesq': 'Buscar',
        }
        headers = {
            'Referer': self.url,  # page refuses the call without this referer
            'Content-Type': "application/x-www-form-urlencoded",
        }
        kwargs = {}
        if self.timeout is not None:
            kwargs['timeout'] = self.timeout

        try:
            response = self.http_client.post(
                self.url,
                data=data,
                headers=headers,
                **kwargs)
        except RequestException:
            return None

        html = response.content

        if html:
            try:
                html = html.decode('latin-1')
            except UnicodeDecodeError:
                pass
            encomenda = Encomenda(numero)
            for status in self._get_all_status_from_html(html):
                encomenda.adicionar_status(status)
            return encomenda
Example #2
0
    def get_encomenda_info(self, numero):
        data = {
            'acao': 'track',
            'objetos': numero,
            'btnPesq': 'Buscar',
        }
        headers = {
            'Referer': self.url,  # page refuses the call without this referer
            'Content-Type': "application/x-www-form-urlencoded",
        }
        kwargs = {}
        if self.timeout is not None:
            kwargs['timeout'] = self.timeout

        try:
            response = self.http_client.post(self.url,
                                             data=data,
                                             headers=headers,
                                             **kwargs)
        except RequestException:
            return None

        html = response.content

        if html:
            try:
                html = html.decode('latin-1')
            except UnicodeDecodeError:
                pass
            encomenda = Encomenda(numero)
            for status in self._get_all_status_from_html(html):
                encomenda.adicionar_status(status)
            return encomenda
Example #3
0
    def get_encomenda_info(self, numero, auth=None):
        if auth is None:
            auth = ("ECT", "SRO")

        kwargs = dict(
            self.default_kwargs,
            objetos=numero,
            usuario=auth[0],
            senha=auth[1])

        response = self.client.service.buscaEventos(**kwargs)
        objeto = response.objeto[0]

        encomenda = Encomenda(numero)
        if objeto.erro:
            pass
        else:
            for evento in objeto.evento:
                data = u"{} {}".format(evento.data, evento.hora)
                status = Status(
                    data=data,
                    local=evento.local,
                    situacao=evento.descricao,
                    detalhes=evento.detalhe)
                encomenda.adicionar_status(status)
        return encomenda
Example #4
0
 def get_encomenda_info(self, numero):
     request = self.http_client.urlopen('%s%s' % (self.url, numero))
     html = request.read()
     request.close()
     if html:
         encomenda = Encomenda(numero)
         [encomenda.adicionar_status(status) for status in self._get_all_status_from_html(html)]
         return encomenda
Example #5
0
 def get_encomenda_info(self, numero):
     request = self.http_client.urlopen('%s%s' % (self.url, numero))
     html = request.read()
     request.close()
     if html.find('Hist') != -1:
         encomenda = Encomenda(numero)
         [encomenda.adicionar_status(status) for status in self._get_all_status_from_html(html)]
         return encomenda
     else:
         raise Exception('invalid code!')
Example #6
0
 def get_encomenda_info(self, numero):
     request = self.http_client.urlopen('%s%s' % (self.url, numero))
     html = request.read()
     request.close()
     if html:
         encomenda = Encomenda(numero)
         [
             encomenda.adicionar_status(status)
             for status in self._get_all_status_from_html(html)
         ]
         return encomenda
Example #7
0
 def get_encomenda_info(self, numero):
     request = self.http_client.urlopen('%s%s' % (self.url, numero))
     html = request.read()
     request.close()
     if html.find('Hist') != -1:
         encomenda = Encomenda(numero)
         [
             encomenda.adicionar_status(status)
             for status in self._get_all_status_from_html(html)
         ]
         return encomenda
     else:
         raise Exception('invalid code!')
Example #8
0
    def get_encomenda_info(self, numero):
        req = self._req(numero)
        kwargs = {}
        if self.timeout is not None:
            kwargs["timeout"] = self.timeout

        try:
            request = self.http_client.urlopen(req, **kwargs)
        except urllib2.HTTPError:
            return None

        html = request.read()
        request.close()
        if html:
            try:
                html = html.decode("latin-1")
            except UnicodeDecodeError:
                pass
            encomenda = Encomenda(numero)
            for status in self._get_all_status_from_html(html):
                encomenda.adicionar_status(status)
            return encomenda
Example #9
0
    def get_encomenda_info(self, numero, auth=None):
        if auth is None:
            auth = ("ECT", "SRO")

        kwargs = dict(self.default_kwargs,
                      objetos=numero,
                      usuario=auth[0],
                      senha=auth[1])

        response = self.client.service.buscaEventos(**kwargs)
        objeto = response.objeto[0]

        encomenda = Encomenda(numero)
        if objeto.erro:
            pass
        else:
            for evento in objeto.evento:
                data = u"{} {}".format(evento.data, evento.hora)
                status = Status(data=data,
                                local=evento.local,
                                situacao=evento.descricao,
                                detalhes=evento.detalhe)
                encomenda.adicionar_status(status)
        return encomenda