Created
August 27, 2008 23:36
-
-
Save rafaelss/7610 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'sinatra' | |
require 'hpricot' | |
require 'open-uri' | |
helpers do | |
def episodes_form | |
body = '<form method="post" action="/"><select name="link">' | |
doc = Hpricot(open("http://podcast.rubyonrails.pro.br/")) | |
(doc/'div.sub').each do |sub| | |
a = sub.next_sibling.search('a').last | |
if a | |
(sub/'h1').each do |h1| | |
number = h1.children[0].inner_text | |
puts number.to_s | |
if number[0] == 35 # igual a # | |
body << '<option value="' + a[:href] + '">Episódio ' + number + ' - ' + h1.children[2].inner_text + '</option>' | |
end | |
end | |
end | |
end | |
body << '</select><button>Ok</button></form>' | |
end | |
end | |
get '/' do | |
episodes_form | |
end | |
post '/' do | |
body = episodes_form | |
doc = Hpricot(open("http://podcast.rubyonrails.pro.br#{params[:link]}")) | |
body << (doc/'div.content ul').last.to_html | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment