Skip to content

Instantly share code, notes, and snippets.

@caironoleto
Created June 29, 2010 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caironoleto/457000 to your computer and use it in GitHub Desktop.
Save caironoleto/457000 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'nokogiri'
require 'open-uri'
require 'sinatra/content_for'
class String
def to_slug
ret = self.strip
ret.gsub! /['`]/,""
ret.gsub! /\s*@\s*/, " at "
ret.gsub! /\s*&\s*/, " and "
ret.gsub! /\s*[^A-Za-z0-9\.\-]\s*/, '-'
ret.gsub! /_+/,"-"
ret.gsub! /\A[_\.]+|[_\.]+\z/,""
ret.downcase!
ret
end
end
get "/" do
stop = []
@guesses = []
doc = Nokogiri::HTML(open("http://www.bolaodamarko.com.br/jogos.php"))
doc.search("div.jogo").each do |game|
title = game.search("h2").first.content
unless title.downcase =~ /grupo/
games = []
game.search("a[title='Ver palpites']").each do |a|
games << [a.children[1].content, a.children[5].content, a.attributes["href"].content.gsub("palpitejogo.php?jogo=", "").to_i]
end
@guesses << {:title => title, :games => games}
end
end
erb :index
end
get "/:id/:team_a/:team_b" do
doc = Nokogiri::HTML(open("http://www.bolaodamarko.com.br/palpitejogo.php?jogo=#{params[:id]}"))
ta = doc.search("td[width='136']")
tb = doc.search("td[width='160']")
@team_a = ta.shift.content
@team_b = tb.shift.content
array = []
for p in 0..(ta.size-1) do
array << [ta[p], tb[p]]
end
narray = array.sort{|x,y| y[0].content.to_i <=> x[0].content.to_i}
guesses = []
narray.each{|p| guesses << "#{p[0].content.to_i} X #{p[1].content.to_i}"}
result = guesses.uniq
@results = []
result.each{|r| @results << [r, guesses.map{|g| g if g == r}.compact.size]}
erb :show
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment