Skip to content

@caironoleto /hackmarkoapp.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.