Created
April 28, 2019 19:38
-
-
Save theist/60abd592a660d658785e8cd05c73ab68 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'json' | |
require 'paint' | |
curl = `curl -s 'https://elecciones28a.porcentual.es/widgets/2019-elecciones/data/00/json/widgets/widget-map.json' -H 'Accept: */*' -H 'Referer: https://newtral.es/resultado-elecciones-28a/' -H 'Origin: https://newtral.es' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Mobile Safari/537.36' --compressed` | |
res = JSON.parse(curl)['resultados'] | |
escrutado = "" | |
res.each do |party| | |
if party.has_key?('porcentajeCensoEscrutado') | |
escrutado = party['porcentajeCensoEscrutado'].to_i / 100.0 | |
next | |
end | |
if party['escanos'].to_i > 0 | |
puts Paint["#{party['siglas']}: #{party['escanos']} escaños, (votos #{party['votos']})", party['color']] | |
end | |
end | |
puts "\nescrutado: #{escrutado}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gem install paint
ruby escrotinio.rb
sample output:
But with coloricos