This file contains hidden or 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
import urllib.request | |
import json | |
api_key = '7ba14b76dcea0086a03f8eca5a3a801f:1:74295566' | |
category = 'editorial' | |
for i in range(5): | |
url = "http://api.nytimes.com/svc/search/v2/articlesearch.json?" \ | |
"q={0}&api-key={1}&page={2}".format(category, api_key, i) | |
h = urllib.request.urlopen(url) | |
result = json.loads(h.read().decode('utf-8')) |
This file contains hidden or 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
from urllib.request import Request, urlopen | |
import json | |
url = "https://api.propublica.org/campaign-finance/v1/2016/president/totals.json" | |
q = Request(url) | |
q.add_header('X-API-Key', 'n8QLPm4lNS2Mfak1bam5X7HlevBAOSoF9epQkX0m') | |
data = urlopen(q).read() | |
data = json.loads(data.decode('utf-8')) |
This file contains hidden or 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
#Pi Generator ref https://mail.python.org/pipermail/edu-sig/2015-September/011317.html | |
def pi_digits(): | |
k, a, b, a1, b1 = 2, 4, 1, 12, 4 | |
while True: | |
p, q, k = k*k, 2*k+1, k+1 | |
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 | |
d, d1 = a//b, a1//b1 | |
while d == d1: | |
yield int(d) | |
a, a1 = 10*(a%b), 10*(a1%b1) |
This file contains hidden or 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
import urllib.request as req | |
proxy = req.ProxyHandler({'http': r'http://user:password@ip:port'}) | |
auth = req.HTTPBasicAuthHandler() | |
opener = req.build_opener(proxy, auth, req.HTTPHandler) | |
req.install_opener(opener) |
This file contains hidden or 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
import urllib.request | |
url = 'http://www.portaltransparencia.gov.br/copa2014/api/rest/empreendimento' | |
resp = urllib.request.urlopen(url).read().decode('utf-8') | |
total = 0 | |
j = 0 | |
while True: | |
abre = '<valorTotalPrevisto>' | |
fecha = '</valorTotalPrevisto>' | |
j = resp.find(abre, j) | |
if j == -1: |
This file contains hidden or 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 | |
url = 'http://www.portaltransparencia.gov.br/copa2014/api/rest/empreendimento' | |
resp = urllib.request.urlopen(url).read().decode('utf-8') | |
total = 0 | |
j = 0 | |
and1 = '<andamento>' | |
and2 = '</andamento>' | |
abre = '<valorTotalPrevisto>' | |
fecha = '</valorTotalPrevisto>' |
This file contains hidden or 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']) |
This file contains hidden or 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
import urllib.request | |
import json | |
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']) | |
print () |
This file contains hidden or 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
import urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escola/' | |
codigo = '35141240' | |
resp = urllib.request.urlopen(url+codigo).read() | |
resp = json.loads(resp.decode('utf-8')) | |
print (resp['nome']) | |
print ('Salas:', resp['salasExistentes']) | |
print ('Computadores:', resp['computadores']+resp['computadoresAdm']+resp['computadoresAlunos']) | |
print ('Formação Docente:', resp['formacaoDocente']) |
This file contains hidden or 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
import urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escolas?nome=' | |
escola = 'embraer' | |
resp = urllib.request.urlopen(url+escola).read() | |
resp = json.loads(resp.decode('utf-8')) | |
for x in resp[1]: | |
print (x['nome']) | |
print ('Código:', x['cod']) | |
print (x['cidade'], x['estado']) |