-
Notifications
You must be signed in to change notification settings - Fork 2
/
CEP.py
31 lines (26 loc) · 953 Bytes
/
CEP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#https://github.com/Wesley-Pinheiro
#executar esta comando no terminal para instalar a biblioteca: pip install pycep_correios
import pycep_correios
#variavel com o CEP para consulta
iCEP = '79814530'
if len(iCEP) == 8:
#chama a consulta do CEP
try:
endereco = pycep_correios.consultar_cep(str(iCEP))
except:
print("Erro ao consultar CEP")
#se as respostas forem vazias nao encontrou o CEP
if endereco['cidade'] != None or endereco['cidade'] != ' ':
#respostas da consulta
print('endereco completo: ' + str(endereco))
print(endereco['end'])
print(endereco['bairro'])
print(endereco['cidade'])
print(endereco['uf'])
print(endereco['cep'])
else:
print('CEP nao localizado')
else:
#cep informado nao esta no formato correto
print('Informe o CEP com 8 caracteres no formato: 00000000')