MCPcopy Index your code
hub / github.com/PostmonAPI/postmon / verifica_cep

Function verifica_cep

PostmonServer.py:76–112  ·  view source on GitHub ↗
(cep)

Source from the content-addressed store, hash-verified

74@route('/cep/<cep:re:\d{5}-?\d{3}>')
75@app_v1.route('/cep/<cep:re:\d{5}-?\d{3}>')
76def verifica_cep(cep):
77 cep = cep.replace('-', '')
78 db = Database()
79 response.headers['Access-Control-Allow-Origin'] = '*'
80
81 result = db.get_one(cep, fields={'_id': False})
82 if result and 'v_date' in result and not expired(result):
83 result.pop('v_date')
84 else:
85 try:
86 info = _get_info_from_source(cep)
87 except ValueError:
88 response.status = "404 O CEP {0} informado nao pode ser "
89 "localizado".format(cep)
90 return
91 except requests.exceptions.RequestException:
92 response.status = '503 Servico Temporariamente Indisponivel'
93 return
94 for item in info:
95 db.insert_or_update(item)
96 result = db.get_one(cep, fields={'_id': False, 'v_date': False})
97
98 if result:
99 response.headers['Cache-Control'] = 'public, max-age=2592000'
100 sigla_uf = result['estado']
101 estado_info = _get_estado_info(db, sigla_uf)
102 if estado_info:
103 result['estado_info'] = estado_info
104 nome_cidade = result['cidade']
105 cidade_info = _get_cidade_info(db, sigla_uf, nome_cidade)
106 if cidade_info:
107 result['cidade_info'] = cidade_info
108 return format_result(result)
109 else:
110 response.status = '404 O CEP %s informado nao pode ser '
111 'localizado' % cep
112 return
113
114
115@app_v1.route('/uf/<sigla>')

Callers

nothing calls this directly

Calls 7

expiredFunction · 0.85
_get_info_from_sourceFunction · 0.85
_get_estado_infoFunction · 0.85
_get_cidade_infoFunction · 0.85
format_resultFunction · 0.85
get_oneMethod · 0.80
insert_or_updateMethod · 0.80

Tested by

no test coverage detected