def get(self):
		id = self.request.get('id')
		try:							
			opener = urllib2.build_opener()
			opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN), ('Content-Type', 'application/json'), ('Accept', 'application/json')]
			result = opener.open(settings.uri('candidatos')+"/"+id)
			profile = json.decode(result.read())
			
			result = opener.open(settings.uri('candidatos')+"/"+id+ "/bens")
			bens = json.decode(result.read())
			profile["bens"] = bens
			
			result = opener.open(settings.uri('candidatos')+"/"+id+ "/doadores")
			doadores = json.decode(result.read())
			profile["doadores"] = doadores
			
			result = opener.open(settings.uri('candidatos')+"/"+id+ "/candidaturas")
			candidaturas = json.decode(result.read())
			profile["candidaturas"] = candidaturas
			
			result = opener.open(settings.uri('candidatos')+"/"+id+ "/estatisticas")
			estatisticas = json.decode(result.read())
			profile["estatisticas"] = estatisticas
		except urllib2.URLError, e:
			profile = []
예제 #2
0
파일: api.py 프로젝트: rafaelnunes/seleicao
def _put_candidate(candidato):
    try:
        opener = urllib2.build_opener()
        opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN),
                             ('Content-Type', 'application/json'), ('Accept', 'application/json')]

        uri = settings.uri('candidato_stats').format(
            candidato_id=candidato['id'])
        result = opener.open(uri)

        candidato_stats = json.decode(result.read())
        if candidato_stats:
            candidato_stats = candidato_stats[0]
        else:
            candidato_stats = {}

        Candidato(candidato_id=int(candidato['id']), 
                  instrucao=candidato['instrucao'], 
                  reeleicao=candidato['reeleicao'], 
                  cargo=candidato['cargo'],
                  estado=candidato['estado'], 
                  nome=candidato['nome'], 
                  foto=candidato['foto'],
                  faltas_plenario=float(candidato_stats.get('faltas_plen', 0)),
                  faltas_comissoes=float(candidato_stats.get('faltas_com', 0))).put()
    except urllib2.URLError, e:
        print '>>>>>>>>>>>>>>>>>>>> %s' % str(e)
        pass
예제 #3
0
def load_partidos():
	ndb.delete_multi(
    	Partido.query().fetch(keys_only=True)
	)
	try:
		opener = urllib2.build_opener()
		opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN), ('Content-Type', 'application/json'), ('Accept', 'application/json')]
		result = opener.open(settings.uri('partidos'))

		partidos = json.decode(result.read())
		for partido in partidos:
			Partido(partido_id=int(partido['partidoId']), sigla=partido['sigla']).put()
	except urllib2.URLError, e:
		print '>>>>>>>>>>>>>>>>>>>> %s' %str(e)
		pass
예제 #4
0
def load_cargos():
	ndb.delete_multi(
    	Cargo.query().fetch(keys_only=True)
	)

	try:
		opener = urllib2.build_opener()
		opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN), ('Content-Type', 'application/json'), ('Accept', 'application/json')]
		result = opener.open(settings.uri('cargos'))

		cargos = json.decode(result.read())
		for cargo in cargos:
			Cargo(cargo_id=int(cargo['cargoId']), nome=cargo['nome']).put()
	except urllib2.URLError, e:
		print '>>>>>>>>>>>>>>>>>>>> %s' %str(e)
		pass
예제 #5
0
def _load_candidato_by_uf(estado):
	cargos = Cargo.query().fetch()
	for cargo in cargos:
		try:
			opener = urllib2.build_opener()
			opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN), ('Content-Type', 'application/json'), ('Accept', 'application/json')]

			uri = settings.uri('candidatos_by_uf_cargo').format(uf=estado.sigla, cargo=cargo.cargo_id)
			result = opener.open(uri)

			candidatos = json.decode(result.read())
			for candidato in candidatos:
				_put_candidate(candidato)

		except urllib2.URLError, e:
			print '>>>>>>>>>>>>>>>>>>>> %s' %str(e)
			pass
예제 #6
0
def load_candidatos():
	ndb.delete_multi(
    	Candidato.query().fetch(keys_only=True)
	)

	try:
		opener = urllib2.build_opener()
		opener.addheaders = [('App-Token', settings.TRANSPARENCIA_TOKEN), ('Content-Type', 'application/json'), ('Accept', 'application/json')]

		uri = settings.uri('candidatos_by_uf_cargo')

		estados = Estado.query().fetch()
		for estado in estados:
			_load_candidato_by_uf(estado)
		
	except urllib2.URLError, e:
		print '>>>>>>>>>>>>>>>>>>>> %s' %str(e)
		pass