#!/usr/bin/env ruby # This script generates a RSS for The Dilbert Blog with full entries, # as opposed to summaries. # Enable using gems I've installed, on Dreamhost # http://nateclark.com/articles/2006/10/20/dreamhost-your-own-packages-and-gems ENV['GEM_PATH'] = "/usr/lib/ruby/gems/1.8:/home/henrik/.gems" require "rubygems" require "feedalizer" URL = "http://dilbertblog.typepad.com/the_dilbert_blog/" CACHE_FILE = "dilbert.cache" CACHE_LIFE = 30 # minutes def uncached? !File.exist?(CACHE_FILE) || (Time.now - File.mtime(CACHE_FILE))/60 > CACHE_LIFE end print "Content-Type: text/xml\n\n" feedalize(URL) do feed.title = "The Dilbert Blog: Full Entries" feed.description = "Dilbert humor, business absurdity, the meaning of life. And full entries." feed.about = URL scrape_items("//div.entry") do |rss_item, html_entry| header = html_entry.at('.entry-header') rss_item.link = header.at('a').attributes['href'] rss_item.date = Time.parse(html_entry.at('.post-footers').inner_text) rss_item.title = header.inner_text rss_item.description = html_entry.at('.entry-body').inner_html end File.open(CACHE_FILE, 'w') {|f| f.write output } # cache output end if uncached? print File.read(CACHE_FILE)