require 'rubygems' require 'open-uri' require 'hpricot' require 'builder' def fetch_twits(url="http://rinexus.com/blog/2009/01/rhode-island-twitter-sound") doc = open(url) { |f| Hpricot(f) } twits = [] (doc/'.content/p').each do |p| p.inner_html.each do |line| matches = line.scan(/@(\w+)/m) twits.concat(matches) unless matches.empty? end end twits.flatten.uniq end def print_twits fetch_twits.each do |twit| puts twit end end def render_opml s = "" x = Builder::XmlMarkup.new(:target => s) x.instruct! :xml, :version => "1.0", :encoding => "utf-8" x.opml('version' => '1.0') do x.head do x.title "RI Nexus Twits" end x.body do x.outline('text' => "RI Nexus Twits") do fetch_twits.each do |twit| x.outline('title' => twit, 'text' => twit, 'type' => 'rss', 'htmlUrl' => "http://twitter.com/#{twit}", 'xmlUrl' => "http://twitter.com/statuses/user_timeline/#{twit}.rss") end end end end puts s end render_opml