Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
postmon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matheus Horstmann
postmon
Commits
cda0859b
Commit
cda0859b
authored
11 years ago
by
Alê Borba
Browse files
Options
Downloads
Plain Diff
Merge pull request #53 from CodingForChange/bug_hunt
Refatoração pra ajudar a resolver o #52
parents
869eac74
3770e5bb
No related branches found
Branches containing commit
Tags
v1.3.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PostmonServer.py
+15
-19
15 additions, 19 deletions
PostmonServer.py
with
15 additions
and
19 deletions
PostmonServer.py
+
15
−
19
View file @
cda0859b
...
...
@@ -21,10 +21,8 @@ def expired(record_date):
def
_get_info_from_source
(
cep
):
tracker
=
CepTracker
()
info
=
tracker
.
track
(
cep
)
if
len
(
info
)
==
0
:
raise
ValueError
()
return
info
...
...
@@ -33,27 +31,25 @@ def _get_info_from_source(cep):
def
verifica_cep
(
cep
):
cep
=
cep
.
replace
(
'
-
'
,
''
)
db
=
Database
()
response
.
headers
[
'
Access-Control-Allow-Origin
'
]
=
'
*
'
try
:
result
=
db
.
get_one
(
cep
,
fields
=
{
'
_id
'
:
False
})
if
not
result
or
not
result
.
has_key
(
'
v_date
'
)
or
expired
(
result
):
try
:
for
item
in
_get_info_from_source
(
cep
):
db
.
insert_or_update
(
item
)
except
ConnectionError
:
response
.
status
=
'
503 Servico Temporariamente Indisponivel
'
result
=
db
.
get_one
(
cep
,
fields
=
{
'
_id
'
:
False
})
if
result
and
result
.
has_key
(
'
v_date
'
)
and
not
expired
(
result
):
result
.
pop
(
'
v_date
'
)
else
:
try
:
info
=
_get_info_from_source
(
cep
)
except
ValueError
:
response
.
status
=
'
404 O CEP %s informado nao pode ser localizado
'
%
cep
return
except
ConnectionError
:
response
.
status
=
'
503 Servico Temporariamente Indisponivel
'
return
for
item
in
info
:
db
.
insert_or_update
(
item
)
result
=
db
.
get_one
(
cep
,
fields
=
{
'
_id
'
:
False
,
'
v_date
'
:
False
})
response
.
headers
[
'
Cache-Control
'
]
=
'
public, max-age=2592000
'
except
ValueError
:
response
.
status
=
'
404 O CEP %s informado nao pode ser localizado
'
%
cep
response
.
headers
[
'
Cache-Control
'
]
=
'
public, max-age=2592000
'
return
result
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment