Last active
October 22, 2019 17:11
-
-
Save fmasanori/4d6b7ea38a28681a513a to your computer and use it in GitHub Desktop.
QEdu exemplo de Busca Avançada: escolas, em funcionamento, sem água, energia e esgoto, mostrando alguns detalhes
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
#The context of this program is a course of an hour to journalists who know nothing about programming in a lab with Python 3 only. | |
import urllib.request | |
import json | |
def analisa_detalhe(cod): | |
url = 'http://educacao.dadosabertosbr.com/api/escola/' | |
resp = urllib.request.urlopen(url+str(cod)).read() | |
resp = json.loads(resp.decode('utf-8')) | |
if int(resp['salasExistentes']) > 1: | |
print ('Salas Existentes:', resp['salasExistentes']) | |
print ('Funcionários:', resp['funcionarios']) | |
print ('Queima Lixo:', resp['lixoQueima']) | |
print ('Sanitário Fora Predio:', resp['sanitarioForaPredio']) | |
url = 'http://educacao.dadosabertosbr.com/api/escolas/buscaavancada?situacaoFuncionamento=1&energiaInexistente=on&aguaInexistente=on&esgotoInexistente=on' | |
resp = urllib.request.urlopen(url).read() | |
resp = json.loads(resp.decode('utf-8')) | |
print ('Número de Escolas em funcionamento sem energia, água e esgoto:', resp[0]) | |
for x in resp[1]: | |
print (x['nome'], x['cod']) | |
print (x['cidade'], x['estado'], x['regiao']) | |
analisa_detalhe(x['cod']) | |
print () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fiz a versão baseada no
asyncio
https://gist.github.com/drgarcia1986/b44f9d61d16cb149dd23Ainda preciso estudar e melhorar esse algoritmo.