Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created July 1, 2015 17:58
Show Gist options
  • Save fmasanori/a428ef783211b0ffdee1 to your computer and use it in GitHub Desktop.
Save fmasanori/a428ef783211b0ffdee1 to your computer and use it in GitHub Desktop.
Copa 2014 todas as obras
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:
break
k = resp.find(fecha, j)
print (resp[j+len(abre):k])
total = total + float (resp[j+len(abre):k])
j = k + len(fecha)
print ('R$ %.2f' %total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment