Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View hackmarkoapp.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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.