Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Last active December 14, 2015 05:09
Show Gist options
  • Save RoxasShadow/5033638 to your computer and use it in GitHub Desktop.
Save RoxasShadow/5033638 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
def puttana(url, what)
candidati = []
voti = []
doc = Nokogiri::HTML(open(url))
doc.xpath('//tr[@class="evid"]/th').each { |p|
if what == :camera
if p.text.end_with?('BERSANI') || p.text.end_with?('BERLUSCONI') || p.text.end_with?('MONTI')
candidati << p.text.split(' ').map {|w| w.capitalize }.join(' ')
end
else
if p.text.end_with?('BERSANI') || p.text.end_with?('BERLUSCONI')
candidati << p.text.split(' ').map {|w| w.capitalize }.join(' ')
end
end
}
doc.xpath('//tr[@class="tot"]/td[@class="num perc"]').each { |p|
voti << p.text
}
Hash[*candidati.zip(voti).flatten].each { |p, v|
puts "#{p} => #{v}%"
}
end
while true
puts '*CAMERA*'
puttana 'http://elezioni.interno.it/politiche/camera130224/C000000000.htm?_=3169', :camera
puts
puts '*SENATO*'
puttana 'http://elezioni.interno.it/politiche/senato130224/S000000000.htm?_=8751', :senato
sleep 3
puts ?- * 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment