Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e00981f
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
- "3.2" | ||
- "3.3" | ||
- "3.4" | ||
script: | ||
- python test_viacep.py | ||
notifications: | ||
email: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# # ViaCEP em Python | ||
|
||
[![Build Status](https://travis-ci.org/leogregianin/viacep-python.svg)](https://travis-ci.org/leogregianin/viacep-python) | ||
|
||
## Buscar informações do CEP com o webservice do site viacep.com.br |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
import unittest | ||
import viacep | ||
|
||
class TestCase(unittest.TestCase): | ||
|
||
def test(self): | ||
test = viacep.ViaCEP('78048000') | ||
self.assertEqual(test.retorna_uf(), 'MT') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
import requests | ||
|
||
class ViaCEP: | ||
|
||
def __init__(self, cep): | ||
self.cep = cep | ||
|
||
def retorna_json_completo(self): | ||
url_api = ('http://www.viacep.com.br/ws/%s/json' % self.cep) | ||
req = requests.get(url_api) | ||
dados_json = json.loads(req.text) | ||
return dados_json | ||
|
||
def retorna_uf(self): | ||
url_api = ('http://www.viacep.com.br/ws/%s/json' % self.cep) | ||
req = requests.get(url_api) | ||
dados_json = json.loads(req.text) | ||
return dados_json['uf'] | ||
|
||
if __name__ == '__main__': | ||
test1 = ViaCEP('78048000') | ||
print(u'%s' % test1.retorna_json_completo()) |