Skip to content

Instantly share code, notes, and snippets.

@pragmaticivan
Forked from caarlos0/elections.rb
Created October 26, 2014 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pragmaticivan/7767d3c79b067444a03f to your computer and use it in GitHub Desktop.
Save pragmaticivan/7767d3c79b067444a03f to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'json'
uri = URI('http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js')
class String; def percent_of(n) "#{(self.to_f / n.to_f * 100.0).round(2)}%"; end; end
begin
data = JSON(Net::HTTP.get_response(uri).body)
system('clear')
puts "\n\n----\n#{data['ht']} - #{data['ea'].percent_of(data['e'])} dos votos apurados\n----"
data['cand'].take(3).each do |candidate|
puts "[#{candidate['n']}] #{candidate['nm']} - #{candidate['v'].percent_of(data['vv'])}"
end
end while sleep(60)
require 'net/http'
require 'uri'
require 'json'
uri = URI('http://divulga.tse.jus.br/2014/divulgacao/oficial/144/dadosdivweb/br/br-0001-e001441-w.js')
class String; def percent_of(n) "#{(self.to_f / n.to_f * 100.0).round(2)}%"; end; end
begin
data = JSON(Net::HTTP.get_response(uri).body)
system('clear')
puts "\n\n----\n#{data['ht']} - #{data['ea'].percent_of(data['e'])} dos votos apurados\n----"
data['cand'].each do |candidate|
puts "[#{candidate['n']}] #{candidate['nm']} - #{candidate['v'].percent_of(data['vv'])}"
end
end while sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment