Skip to content

Commit

Permalink
Primeiro commit
Browse files Browse the repository at this point in the history
  • Loading branch information
leogregianin committed Mar 29, 2016
0 parents commit e00981f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
@@ -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
5 changes: 5 additions & 0 deletions README.md
@@ -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
12 changes: 12 additions & 0 deletions test_viacep.py
@@ -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()
26 changes: 26 additions & 0 deletions viacep.py
@@ -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())

0 comments on commit e00981f

Please sign in to comment.