mph.paste.lol / oohpml.rb · 1 year ago·
!/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.
-
Install the feedbag gem:
gem install feedbag
(you might need to usesudo gem install feedbag
if you're using your system ruby -
Download it.
-
cd
to the directory you downloaded it to. -
run it with
ruby ohhpml.rb
. -
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 = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
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