-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Portando código do python 2 para 3 #13
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
language: python | ||
|
||
python: | ||
- "3.6" | ||
|
||
before_install: pip install -r requirements.txt | ||
|
||
script: nosetests | ||
script: nosetests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from correios import EncomendaRepository | ||
from royal import RoyalMail | ||
from dhl_gm import DhlGmTracker | ||
from packtrack.correios import EncomendaRepository | ||
from packtrack.royal import RoyalMail | ||
from packtrack.dhl_gm import DhlGmTracker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usa imports relativos ( |
||
|
||
|
||
class Correios(object): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def get(self, numero, auth=None): | |
return func(numero, **kwargs) | ||
|
||
def _init_scraper(self, backend): | ||
from scraping import CorreiosWebsiteScraper, CorreiosRastroService | ||
from packtrack.scraping import CorreiosWebsiteScraper, CorreiosRastroService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesma coisa, use import relativo. |
||
if backend is None: | ||
backend = 'www2' | ||
|
||
|
@@ -36,8 +36,8 @@ def __init__(self, numero): | |
def adicionar_status(self, status): | ||
d = datetime | ||
self.status.append(status) | ||
t_format = self.validar_data(status.data) | ||
self.status.sort(lambda x, y: 1 if d.strptime(x.data, t_format) > d.strptime(y.data, t_format) else -1) | ||
self.status.sort( | ||
key=lambda x: d.strptime(x.data, self.validar_data(x.data))) | ||
|
||
def validar_data(self, data): | ||
if re.match('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$', data): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import os | ||
import re | ||
from HTMLParser import HTMLParser | ||
|
||
from BeautifulSoup import BeautifulSoup | ||
from bs4 import BeautifulSoup | ||
import requests | ||
from requests.exceptions import RequestException | ||
from zeep import Client as Zeep | ||
from zeep.cache import InMemoryCache | ||
from zeep.transports import Transport | ||
|
||
from correios import Encomenda, Status | ||
from packtrack.correios import Encomenda, Status | ||
|
||
|
||
class CorreiosWebsiteScraper(object): | ||
|
@@ -50,7 +49,7 @@ def get_encomenda_info(self, numero): | |
|
||
if html: | ||
try: | ||
html = html.decode('latin-1') | ||
html = html.encode('latin-1') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não tenho certeza se isso faz sentido. |
||
except UnicodeDecodeError: | ||
pass | ||
encomenda = Encomenda(numero) | ||
|
@@ -59,36 +58,35 @@ def get_encomenda_info(self, numero): | |
return encomenda | ||
|
||
def _text(self, value): | ||
value = BeautifulSoup(value.strip()).text | ||
return value.replace(' ', ' ') | ||
value = BeautifulSoup(value.strip(), 'lxml').text | ||
return value.replace(' ', ' ').replace('\xa0',' ') | ||
|
||
def _get_all_status_from_html(self, html): | ||
status = [] | ||
html_parser = HTMLParser() | ||
if "<table" not in html: | ||
if b'<table' not in html: | ||
return status | ||
html_info = re.search('.*(<table.*</table>).*', html, re.S) | ||
html_info = re.search(b'.*(<table.*</table>).*', html, re.S) | ||
if not html_info: | ||
return status | ||
|
||
table = html_info.group(1) | ||
soup = BeautifulSoup(table) | ||
soup = BeautifulSoup(table, 'lxml') | ||
|
||
for tr in soup.table: | ||
try: | ||
tds = tr.findAll('td') | ||
except AttributeError: | ||
continue | ||
for td in tds: | ||
content = td.renderContents().replace('\r', ' ') \ | ||
.split('<br />') | ||
class_ = td['class'] | ||
content = td.renderContents().replace(b'\r', b' ') \ | ||
.split(b'<br/>') | ||
class_ = td['class'][0] | ||
if class_ == 'sroDtEvent': | ||
data = '%s %s' % (content[0].strip(), content[1].strip()) | ||
data = '%s %s' % (content[0].strip().decode(), content[1].strip().decode()) | ||
local = '/'.join(self._text(content[2]).rsplit(' / ', 1)).upper() | ||
elif class_ == 'sroLbEvent': | ||
situacao = html_parser.unescape(self._text(content[0])) | ||
detalhes = html_parser.unescape(self._text(content[1])) | ||
situacao = self._text(content[0].decode()) | ||
detalhes = self._text(content[1].decode()) | ||
if detalhes: | ||
detalhes = u'%s %s' % (situacao, detalhes) | ||
status.append(Status(data=data, local=local, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
BeautifulSoup==3.2.1 | ||
argparse==1.2.1 | ||
beautifulsoup4==4.3.2 | ||
lxml==2.3.5 | ||
mockito==0.5.1 | ||
beautifulsoup4==4.6.0 | ||
lxml==3.8.0 | ||
mockito==1.0.12 | ||
requests==2.18.1 | ||
wsgiref==0.1.2 | ||
zeep==1.6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisa também rodar no
python 2.7
.