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
e25e01b7
Commit
e25e01b7
authored
12 years ago
by
Iuri de Silvio
Browse files
Options
Downloads
Patches
Plain Diff
Removendo codigo duplicado
parent
4134bf5f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
correios.py
+5
-2
5 additions, 2 deletions
correios.py
correios_server.py
+2
-8
2 additions, 8 deletions
correios_server.py
with
7 additions
and
10 deletions
correios.py
+
5
−
2
View file @
e25e01b7
...
...
@@ -4,6 +4,9 @@ import requests
import
unicodedata
import
re
def
_normalize_unicode
(
text
):
return
unicodedata
.
normalize
(
'
NFKD
'
,
text
).
encode
(
'
ascii
'
,
'
ignore
'
)
if
isinstance
(
text
,
unicode
)
else
text
class
CepTracker
():
def
__init__
(
self
):
self
.
url
=
'
http://m.correios.com.br/movel/buscaCepConfirma.do
'
...
...
@@ -38,9 +41,9 @@ class CepTracker():
if
(
index
==
2
):
for
j
,
text
in
enumerate
(
text
.
split
(
'
/
'
)):
data
[
self
.
fields
[
index
][
j
]]
=
unicodedata
.
normalize
(
'
NFKD
'
,
text
.
strip
()).
encode
(
'
ascii
'
,
'
ignore
'
)
if
isinstance
(
text
,
unicode
)
else
text
.
strip
()
data
[
self
.
fields
[
index
][
j
]]
=
_normalize_unicode
(
text
.
strip
()
)
else
:
data
[
self
.
fields
[
index
]]
=
unicodedata
.
normalize
(
'
NFKD
'
,
text
).
encode
(
'
ascii
'
,
'
ignore
'
)
if
isinstance
(
text
,
unicode
)
else
text
data
[
self
.
fields
[
index
]]
=
_normalize_unicode
(
text
)
index
+=
1
...
...
This diff is collapsed.
Click to expand it.
correios_server.py
+
2
−
8
View file @
e25e01b7
...
...
@@ -35,21 +35,15 @@ def verifica_cep(cep):
ceps
=
db
.
ceps
result
=
ceps
.
find_one
({
'
cep
'
:
cep
},
fields
=
{
'
_id
'
:
False
})
from
datetime
import
date
info
=
None
if
not
result
or
not
result
.
has_key
(
'
v_date
'
):
info
=
_get_info_from_correios
(
cep
)
map
(
lambda
x
:
ceps
.
save
(
x
),
info
)
result
=
ceps
.
find_one
({
'
cep
'
:
cep
},
fields
=
{
'
_id
'
:
False
,
'
v_date
'
:
False
})
elif
expired
(
result
):
info
=
_get_info_from_correios
(
cep
)
map
(
lambda
x
:
ceps
.
update
({
'
cep
'
:
x
[
'
cep
'
]},
{
'
$set
'
:
x
}),
info
)
result
=
ceps
.
find_one
({
'
cep
'
:
cep
},
fields
=
{
'
_id
'
:
False
,
'
v_date
'
:
False
})
else
:
result
=
ceps
.
find_one
({
'
cep
'
:
cep
},
fields
=
{
'
_id
'
:
False
,
'
v_date
'
:
False
})
result
=
ceps
.
find_one
({
'
cep
'
:
cep
},
fields
=
{
'
_id
'
:
False
,
'
v_date
'
:
False
})
except
ValueError
:
result
=
dict
(
status
=
'
404
'
,
...
...
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