def get(self):
     result = ''
     estados = cargos = []
     try:
         estados = Estado.query().fetch()
         cargos = Cargo.query().fetch()
         estados = sorted(estados, key=lambda x: x.sigla)
         cargos = sorted(cargos, key=lambda x: x.cargo_id)
     except urllib2.URLError, e:
         result = str(e)
Exemplo n.º 2
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
Exemplo n.º 3
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