Last active
December 1, 2017 14:27
-
-
Save findcep/acc0229b594a97c02d0d29c0e1cfaf08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') | |
API_CEP_BASE_URL = 'https://api.findcep.com/v1/cep/{cep}.json' | |
headers = {'Referer': 'https://your-site.com'} | |
cep_request = requests.get(API_CEP_BASE_URL.format(cep=CEP_SEARCH) , headers=headers) | |
print(cep_request.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment