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
23b4b334
Commit
23b4b334
authored
12 years ago
by
Iuri de Silvio
Browse files
Options
Downloads
Patches
Plain Diff
Primeiros testes passando
parent
d8670162
No related branches found
Branches containing commit
Tags
v1.3.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
correios.py
+9
-10
9 additions, 10 deletions
correios.py
test/correios_test.py
+55
-0
55 additions, 0 deletions
test/correios_test.py
with
64 additions
and
10 deletions
correios.py
+
9
−
10
View file @
23b4b334
# encoding: utf-8
from
datetime
import
datetime
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
'
...
...
@@ -25,7 +22,7 @@ class CepTracker():
def
track
(
self
,
cep
):
itens
=
self
.
_get_infos_
(
cep
)
index
=
0
index
=
4
-
len
(
itens
)
data
=
dict
()
for
item
in
itens
:
...
...
@@ -34,16 +31,18 @@ class CepTracker():
index
=
0
self
.
result
.
append
(
data
)
data
=
dict
()
data
[
"
v_date
"
]
=
datetime
.
now
()
# TODO: definir v_date apenas uma vez
data
[
"
v_date
"
]
=
datetime
.
now
()
text
=
re
.
sub
(
'
\s+
'
,
'
'
,
item
.
text
.
strip
())
if
(
index
==
2
):
for
j
,
text
in
enumerate
(
text
.
split
(
'
/
'
)):
data
[
self
.
fields
[
index
][
j
]]
=
_normalize_unicode
(
text
.
strip
())
cidade
,
estado
=
text
.
split
(
'
/
'
,
1
)
data
[
'
cidade
'
]
=
cidade
.
strip
()
data
[
'
estado
'
]
=
estado
.
split
(
'
-
'
)[
0
].
strip
()
else
:
data
[
self
.
fields
[
index
]]
=
_normalize_unicode
(
text
)
data
[
self
.
fields
[
index
]]
=
text
index
+=
1
...
...
This diff is collapsed.
Click to expand it.
test/correios_test.py
0 → 100644
+
55
−
0
View file @
23b4b334
# encoding: utf-8
import
unittest
import
correios
class
CorreiosTest
(
unittest
.
TestCase
):
def
test_cep_com_rua
(
self
):
'''
Logradouro: Rua Rocha
Bairro: Bela Vista
Localidade / UF: São Paulo /SP
CEP: 01330000
'''
tracker
=
correios
.
CepTracker
()
result
=
tracker
.
track
(
'
01330000
'
)
self
.
assertTrue
(
len
(
result
)
==
1
)
self
.
assertEqual
(
result
[
0
][
'
cep
'
],
'
01330000
'
)
self
.
assertEqual
(
result
[
0
][
'
logradouro
'
],
'
Rua Rocha
'
)
self
.
assertEqual
(
result
[
0
][
'
cidade
'
],
u
'
São Paulo
'
)
self
.
assertEqual
(
result
[
0
][
'
estado
'
],
'
SP
'
)
self
.
assertIsNotNone
(
result
[
0
][
'
v_date
'
])
def
test_cep_sem_rua
(
self
):
'''
Localidade / UF: Jordão (Guarapuava) /PR - - Povoado
CEP: 85100000
'''
tracker
=
correios
.
CepTracker
()
result
=
tracker
.
track
(
'
85100000
'
)
self
.
assertTrue
(
len
(
result
)
==
1
)
self
.
assertEqual
(
result
[
0
][
'
cep
'
],
'
85100000
'
)
self
.
assertEqual
(
result
[
0
][
'
cidade
'
],
u
'
Jordão (Guarapuava)
'
)
self
.
assertEqual
(
result
[
0
][
'
estado
'
],
'
PR
'
)
self
.
assertIsNotNone
(
result
[
0
][
'
v_date
'
])
def
test_cep_inexistente
(
self
):
'''
CEP: 99999999
'''
tracker
=
correios
.
CepTracker
()
result
=
tracker
.
track
(
'
99999999
'
)
self
.
assertTrue
(
len
(
result
)
==
0
)
# TODO: existe CEP com mais de um resultado?
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