Skip to content

Commit 6176012

Browse files
committed
Merge pull request #75 from thiagodds/master
Logs no CEP tracker. Close #63.
2 parents fa56778 + e8ff7a9 commit 6176012

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

CepTracker.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,37 @@
44

55
import requests
66
import re
7+
import logging.config
8+
import os
9+
import yaml
710

811

912
class CepTracker():
1013

1114
def __init__(self):
15+
self.log_path = 'log.yaml'
16+
self._config_log_file()
17+
self.logger = logging.getLogger(__name__)
18+
1219
self.url = 'http://m.correios.com.br/movel/buscaCepConfirma.do'
1320

21+
def _config_log_file(self):
22+
with open(self.log_path, 'rt') as f:
23+
config = yaml.load(f.read())
24+
logging.config.dictConfig(config)
25+
1426
def _request(self, cep):
1527
response = requests.post(self.url, data={
1628
'cepEntrada': cep,
1729
'tipoCep': '',
1830
'cepTemp': '',
1931
'metodo': 'buscarCep'
2032
})
21-
response.raise_for_status()
33+
try:
34+
response.raise_for_status()
35+
except requests.exceptions.HTTPError as ex:
36+
logging.error('Erro request site Correios', exc_info=True)
37+
raise ex
2238
return response.text
2339

2440
def _get_infos_(self, cep):

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ test: pep8
55

66
.PHONY: pep8
77
pep8:
8-
@flake8 * --ignore=F403,F401 --exclude=requirements.txt,*.pyc,*.md,COPYING,Makefile,*.wsgi,*celerybeat-schedule*
8+
@flake8 * --ignore=F403,F401 --exclude=requirements.txt,*.pyc,*.md,COPYING,Makefile,*.wsgi,*celerybeat-schedule*,*.yaml,*.log

log.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 1
2+
formatters:
3+
simple:
4+
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
5+
6+
handlers:
7+
info_file_handler:
8+
class: logging.handlers.RotatingFileHandler
9+
level: ERROR
10+
formatter: simple
11+
filename: errors.log
12+
maxBytes: 10485760
13+
backupCount: 20
14+
encoding: utf-8
15+
16+
loggers:
17+
__name__:
18+
level: ERROR
19+
handlers: [info_file_handler]
20+
propagate: no
21+
22+
root:
23+
handlers: [info_file_handler]

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ packtrack==0.1.0
88
xmltodict
99
flake8
1010
celery[mongodb]
11+
PyYAML==3.10

0 commit comments

Comments
 (0)