Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'hpricot'
- require 'open-uri'
- # update the database with the actual titles from each site
- Blog.all.each do |b|
- puts b.url
- begin
- doc = Hpricot(open(b.url.strip))
- title = (doc/"html/*/title/").to_s
- if title
- b.url = b.url.strip
- b.blog_name = title.strip
- else
- b.blog_name = b.author
- end
- b.save
- rescue
- b.destroy
- end
- end
- # update the database with feed info
- Blog.all.each do |b|
- puts b.url
- begin
- doc = Hpricot(open(b.url.strip))
- links = (doc/"link[@rel='alternate']")
- href, feed_type = nil, nil
- if links
- if links.size > 1
- tmp = links.select{|l| l.attributes['title'] =~ /All/ || l.attributes['title'] !~ /comment/ }
- links = tmp if tmp
- end
- href = links.first.attributes['href']
- feed_type = links.first.attributes['type'] rescue ""
- end
- if href
- puts "feed: #{href} - type: #{feed_type}"
- b.feed = href =~ /^http/ ? href.strip : b.url.strip + href.strip
- b.feed_type = feed_type.strip
- b.save
- else
- puts "NOT FOUND"
- end
- rescue => e
- puts e
- end
- end
- # prints out each html table line
- Blog.all(:order => :random_number).each do |b|
- puts <<-EOF
- <tr>
- <td><a href="#{b.url}" target="_blank">#{b.blog_name}</a></td>
- <td>#{b.author}</td>
- </tr>
- EOF
- end
- # prints out each OPML outline row
- Blog.all(:order => :random_number, :conditions => "feed <> ''").each do |b|
- puts <<-EOF
- <outline text="#{b.blog_name}"
- title="#{b.blog_name}" type="rss"
- xmlUrl="#{b.feed}" htmlUrl="#{b.url}"/>
- EOF
- end
Add Comment
Please, Sign In to add comment