Skip to content

Instantly share code, notes, and snippets.

@theist
Created April 28, 2019 19:38
Show Gist options
  • Save theist/60abd592a660d658785e8cd05c73ab68 to your computer and use it in GitHub Desktop.
Save theist/60abd592a660d658785e8cd05c73ab68 to your computer and use it in GitHub Desktop.
#!/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}%"
@theist
Copy link
Author

theist commented Apr 28, 2019

gem install paint
ruby escrotinio.rb

sample output:

PSOE: 131 escaños, (votos 2540826)
PP: 65 escaños, (votos 1428222)
Cs: 53 escaños, (votos 1209270)
UNIDAS PODEMOS: 32 escaños, (votos 1021696)
VOX: 023 escaños, (votos 00810216)
ERC-SOBIRANISTES: 015 escaños, (votos 00298294)
ECP-GUANYEM EL CANVI: 007 escaños, (votos 00171328)
JxCAT-JUNTS: 007 escaños, (votos 00151317)
EAJ-PNV: 006 escaños, (votos 00278073)
EH Bildu: 004 escaños, (votos 00171428)
NA+: 002 escaños, (votos 00054663)
CCa-PNC: 002 escaños, (votos 00000387)
COMPROMÍS 2019: 001 escaños, (votos 00038945)
PRC: 001 escaños, (votos 00021678)
CpM: 001 escaños, (votos 00000134)

escrutado: 33.12%

But with coloricos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment