From: Dave Thomas Date: 2004-12-17T06:28:03+09:00 Subject: Re: commit2html.rb or rss2html.rb On Dec 16, 2004, at 12:07, Bil Kleb wrote: > The other month we hooked Dave's commit2rss.rb script up > to our CVS repository to gain an RSS feed. (Thanks Dave!) > > Now we'd like to display the RSS feed in a sidebar. What's > the best method to do this? Currently our web person is > using some third-party converter that produces some rather > ugly HTML. My Dr Dobbs article has a trivial program to do exactly that. Here's a variant of it that we use on the PragProg site to create some HTML which is injected into Mike Clark's automation page. It reads his blog's RSS, then uploads a converted file to our website. Cheers Dave # Such down the top 'n' articles from an RSS feed # and summarize for a web site require 'rss/0.9' require 'open-uri' require 'rdoc/template' require 'net/ftp' TEMPLATE = %{
START:entries
%title%
%description%
END:entries
} TMP_FILE = "/tmp/topfive" BLOG_URL = 'http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/synopsis.rss? count=5' open(BLOG_URL) do |http| result = RSS::Parser.parse(http.read, false) entries = result.items.map do |item| { 'title' => item.title, 'link' => item.link, 'description' => item.description } end File.open(TMP_FILE, "w") do |f| t = TemplatePage.new(TEMPLATE) t.write_html_on(f, 'entries' => entries) end end Net::FTP.open('www.yoursite.com') do |ftp| ftp.login('user', 'passwd') ftp.chdir('somedir') ftp.put(TMP_FILE, 'topfive', 1024) end