Skip to content

Commit

Permalink
Merge pull request #75 from thiagodds/master
Browse files Browse the repository at this point in the history
Logs no CEP tracker. Close #63.
  • Loading branch information
iurisilvio committed Jan 12, 2014
2 parents fa56778 + e8ff7a9 commit 6176012
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
18 changes: 17 additions & 1 deletion CepTracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,37 @@

import requests
import re
import logging.config
import os
import yaml


class CepTracker():

def __init__(self):
self.log_path = 'log.yaml'
self._config_log_file()
self.logger = logging.getLogger(__name__)

self.url = 'http://m.correios.com.br/movel/buscaCepConfirma.do'

def _config_log_file(self):
with open(self.log_path, 'rt') as f:
config = yaml.load(f.read())
logging.config.dictConfig(config)

def _request(self, cep):
response = requests.post(self.url, data={
'cepEntrada': cep,
'tipoCep': '',
'cepTemp': '',
'metodo': 'buscarCep'
})
response.raise_for_status()
try:
response.raise_for_status()
except requests.exceptions.HTTPError as ex:
logging.error('Erro request site Correios', exc_info=True)
raise ex
return response.text

def _get_infos_(self, cep):
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test: pep8

.PHONY: pep8
pep8:
@flake8 * --ignore=F403,F401 --exclude=requirements.txt,*.pyc,*.md,COPYING,Makefile,*.wsgi,*celerybeat-schedule*
@flake8 * --ignore=F403,F401 --exclude=requirements.txt,*.pyc,*.md,COPYING,Makefile,*.wsgi,*celerybeat-schedule*,*.yaml,*.log
23 changes: 23 additions & 0 deletions log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

handlers:
info_file_handler:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: simple
filename: errors.log
maxBytes: 10485760
backupCount: 20
encoding: utf-8

loggers:
__name__:
level: ERROR
handlers: [info_file_handler]
propagate: no

root:
handlers: [info_file_handler]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packtrack==0.1.0
xmltodict
flake8
celery[mongodb]
PyYAML==3.10

0 comments on commit 6176012

Please sign in to comment.