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