gist: 7610 Download_button fork
public
Public Clone URL: git://gist.github.com/7610.git
Text
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
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

Owner

rafaelss

Revisions