#!/usr/bin/env ruby =begin oohpml.rb does the bare minimum to make an OPML file out of URLs found in http://ooh.directory's new sites RSS feed. 1. Install the feedbag gem: `gem install feedbag` (you might need to use `sudo gem install feedbag` if you're using your system ruby 2. Download it. 3. `cd` to the directory you downloaded it to. 4. run it with `ruby ohhpml.rb`. 5. Import the resulting OPML file into your RSS reader, which hopefully will put it in the 'ooh' directory for you instead of messing up your carefully curated feeds. =end require 'rss' require 'open-uri' require 'feedbag' require 'rexml/Document' include REXML # Where do we want to put the output? path="ooh-directory.opml" # Where do we find ooh.directory's new feeds? url = 'https://ooh.directory/feeds/recently-added.xml' # Taking the easy way out of constructing the initial OPML feed_setup = < ooh Newest Feeds Mike Hall mike@puddingtime.org EOF doc = Document.new feed_setup # Read the RSS file from ooh.directory URI.open(url) do |rss| feed = RSS::Parser.parse(rss) feed.items.each do |item| folder = doc.root.get_elements('//outline').first feeds = Feedbag.find item.link feed_link = feeds[0] feed = folder.push(Element.new('outline')) feed.add_attribute('title', item.title) feed.add_attributes({ 'text' => item.title, 'title' => item.title, 'htmlURL' => item.link, 'xmlUrl' => feed_link, 'category' => 'oohDirectory' }) end end # Write it all out to the path you set at the top of the script File.open(path,"w") do |data| doc.write(data) end