Created
October 9, 2014 13:23
-
-
Save fmasanori/2fab1b475e916574d8c4 to your computer and use it in GitHub Desktop.
Resultados das eleições 2014 Python 3 (adaptado Vinicius Marangoni)
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
#versão Python 3 de http://pastebin.com/uRnDZaTz (Vinicius Marangoni) | |
import urllib.request | |
import json | |
url = 'http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js' | |
def main(): | |
resp = urllib.request.urlopen(url).read() | |
resp = json.loads(resp.decode('utf-8')) | |
candidatos = resp['cand'] | |
vv = float(resp['vv']) | |
lista = [] | |
for c in candidatos: | |
lista.append((float(c['v']), c['nm'])) | |
porcentagem = (float(c['v']) / vv) * 100 | |
if(porcentagem > 10): | |
print ("%s:%.2f%%" %(c['nm'], porcentagem)) | |
apurados = float(resp['ea']) / float(resp['e']) | |
apurados *= 100 | |
print("\n%.02f%% Apurados" %(apurados)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá @fmasanori , O segundo turno usa o mesmo .js?
Onde que posso achar esse .js?