Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created August 27, 2008 23:36
Show Gist options
  • Save rafaelss/7610 to your computer and use it in GitHub Desktop.
Save rafaelss/7610 to your computer and use it in GitHub Desktop.
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