Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built main structure and filled methods #26

Merged
merged 6 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
=======
methods
=======
===============================
Congresso Em Numeros API Client
===============================

This is a Python Client for the legislative federal houses of Brazil.

Add a short description here!

We intend to cover and maintain all the API endpoints from Camara dos Deputados and Senado Federal

Description
===========

A longer description of your project goes here...
To use the Camara Client just::

import cn_api_client as cn

camara = cn.Camara()
Note
====

Expand Down
4 changes: 4 additions & 0 deletions methods/__init__.py → cn_api_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
import pkg_resources

from .camara import Camara

try:
__version__ = pkg_resources.get_distribution(__name__).version
except:
__version__ = 'unknown'


31 changes: 31 additions & 0 deletions cn_api_client/camara/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from .deputados import DeputadosClient
from .orgaos import OrgaosClient
from .proposicoes import ProposicoesClient
from .sessoesreunioes import SessoesClient

class Camara(object):
"""
Camara dos Deputados Federal of Brazil low-level client. Provides a mapping from Python to REST endpoints.

The instance has attributes ``deputados``, ``orgaos``, ``proposicoes``, ``sessoesreunioes``,
that provide access to instances of
:class:`~cn_api_client.camara.DeputadosClient`,
:class:`~cn_api_client.camara.OrgaosClient`,
:class:`~cn_api_client.camara.ProposicoesClient` and
:class:`~cn_api_client.camara.SessoesClient` respectively. This is the
preferred (and only supported) way to get access to those classes and their
methods.

You can initialize your connection class by:

camara = cn_api_client.Camara()

and you'll be ready to use the API on your Python projetct.
"""

def __init__(self):

self.deputados = DeputadosClient()
self.orgaos = OrgaosClient()
self.proposicoes = ProposicoesClient()
self.sessoes = SessoesClient()
98 changes: 98 additions & 0 deletions cn_api_client/camara/deputados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from ..connection import Connection
from ..utils import _make_url

class DeputadosClient(Connection):

def obter_deputados(self):
"""
Retorna os deputados em exercício na Câmara dos Deputados

API ENDPOINT:
`<http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDeputados>`

API DOC:
'http://www2.camara.leg.br/transparencia/dados-abertos/dados-abertos-legislativo/webservices/deputados/obterdeputados'

This method does not have input parameters
"""

return self.perform_request('http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDeputados')

def obter_detalhes_deputado(self, ideCadastro=None, numLegislatura=None):
"""
Retorna detalhes dos deputados com histórico de participação em comissões, períodos de exercício,
filiações partidárias e liderancas.

API ENDPOINT:
http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDetalhesDeputado?ideCadastro=141428&numLegislatura=

API DOC:
http://www2.camara.leg.br/transparencia/dados-abertos/dados-abertos-legislativo/webservices/deputados/obterDetalhesDeputado

Args:
ideCadastro: String(Optinal):: Identificador do deputado obtido na chamada ao ObterDeputados.
numLegislatura: Int(Opcional) Número da legislatura. Campo vazio, todas as legislaturas do Deputado.
"""
base_url = 'http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDetalhesDeputado?'
params = dict([('ideCadastro', ideCadastro),
('numLegislatura', numLegislatura)])

return self.perform_request(_make_url(api_house='camara',
base_url=base_url,
params=params))


def obter_lideres_bancadas(self):
"""
Retorna os deputados líderes e vice-líderes em exercício das bancadas dos partidos

API ENDPOINT:
http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterLideresBancadas

API DOC:
http://www2.camara.leg.br/transparencia/dados-abertos/dados-abertos-legislativo/webservices/deputados/obterlideresbancadas

This method does not have input parameters
"""

return self.perform_request('http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterLideresBancadas')


def obter_partidos(self):
"""
Retorna os partidos com representação na Câmara dos Deputados

API ENDPOINT:
http://www.camara.gov.br/SitCamaraWS/Deputados.asmx/ObterPartidosCD

API DOC:
http://www2.camara.leg.br/transparencia/dados-abertos/dados-abertos-legislativo/webservices/deputados/obterpartidosCD

This method does not have input parameters
"""

return self.perform_request('http://www.camara.gov.br/SitCamaraWS/Deputados.asmx/ObterPartidosCD')

# This API endpoint is giving 403 ERROR
def obter_partidos_bloco(self, idBloco=None, numLegislatura=None):
"""
Retorna os blocos parlamentares na Câmara dos Deputados.

API ENDPOINT:
http://www2.camara.leg.br/transparencia/dados-abertos/dados-abertos-legislativo/webservices/deputados/obterPartidosBlocoCD

API DOC:
http://www.camara.gov.br/SitCamaraWS/Deputados.asmx/ObterPartidosBlocoCD?numLegislatura=54&idBloco=

Args:
ideCadastro: String(Optinal):: ID do Bloco Parlamentar
numLegislatura: Int(Opcional):: Número da Legislatura. Campo Vazio, legislatura atual. Apenas legislatura 53 em diante.
"""

base_url = 'http://www.camara.gov.br/SitCamaraWS/Deputados.asmx/ObterPartidosBlocoCD?'
params = dict([('idBloco', idBloco),
('numLegislatura', numLegislatura)])

return self.perform_request(_make_url(api_house='camara',
base_url=base_url,
params=params))
Loading