Created
April 19, 2011 18:51
-
-
Save pstengel/929242 to your computer and use it in GitHub Desktop.
Get Mega Millions stats, parse them, and show lagging and trending numbers
This file contains 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 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'pp' | |
doc = Nokogiri::HTML(open "http://megamillions.com/numbers/pastdrawings.asp") | |
standard = Hash.new | |
mega = Hash.new | |
1.upto(56) do |t| | |
standard[t] = 0 | |
mega[t] = 0 if t <= 46 | |
end | |
doc.css('span.textblack').each do |s| | |
if s.content =~ /Mega Ball/ | |
content = s.content.scan(/[0-9]+/) | |
content.first(5).each do |n| | |
standard[n.to_i] += 1 | |
end | |
mega[content.last.to_i] += 1 | |
end | |
end | |
print "Trending: " | |
standard.sort {|a,b| b[1] <=> a[1]}.first(5).sort {|a,b| a[0] <=> b[0]}.each do |k, v| | |
print "#{k}, " | |
end | |
puts "Mega: " + mega.sort {|a,b| b[1] <=> a[1]}.first[0].to_s | |
print "Lagging: " | |
standard.sort {|a,b| a[1] <=> b[1]}.first(5).sort {|a,b| a[0] <=> b[0]}.each do |k, v| | |
print "#{k}, " | |
end | |
puts "Mega: " + mega.sort {|a,b| a[1] <=> b[1]}.first[0].to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment