Skip to content

Instantly share code, notes, and snippets.

View findcep_search_cep.py
#!/usr/bin/env python
import requests
def validate_field(field):
cep = "".join(field.replace("-"," ").split())
if cep.isdigit() and len(cep) == 8:
return cep
raise Exception('CEP "{field}" Format Invalid'.format(field=field))
CEP_SEARCH = validate_field('01001001')
View findcep_search_address.py
#!/usr/bin/env python
import requests
API_ADDRESS_BASE_URL = 'https://api.findcep.com/v1/endereco/{uf}/{cidade}/{endereco}'
HEADERS = {'Referer': 'https://www.your-site.com'}
def validate_field(field):
''' normalize string with replace of all spaces or tabs for "+" '''
return "+".join(field.split())
View findcep.js
const validate_cep = (cep) => {
cep = cep.replace(/[^0-9]/gi, "");
if (cep.length == 8) {
return cep;
}
throw `CEP "${cep}" format invalid`
}
const apiCep = (cep) => `https://api.findcep.com/v1/cep/${cep}.json`
let cep_search = validate_cep('01001-001');
You can’t perform that action at this time.