Lotus Connections Communities topics+replies feeds to OPML

| geek, lotus, ruby

Keeping track of discussions in Lotus Connections Communities can be difficult, so I thought I’d use a feed reader to read new forum topics and replies. Instead of subscribing to each community by hand, I wrote a Ruby script that generated an OPML file, which I then imported into FeedDemon. Win!

Here’s the script:

#!/usr/bin/ruby

email = ARGV[0]
password = ARGV[1]

require 'rubygems'
require 'rexml/document'
require 'open-uri'
require 'cgi'
require 'net/https'
base_url = 'https://w3.ibm.com/connections/communities/service/atom/'
url = base_url + 'communities/my'
opml = REXML::Document.new('<opml version="1.0"><head></head><body></body></opml>')
body = opml.elements['opml/body']
while url
  # Fetch the page
  $stderr.puts "Fetching " + url
  begin
    my_communities = REXML::Document.new open(url)
  rescue OpenURI::HTTPError
    begin
      my_communities = REXML::Document.new open(url, 
                                                {:http_basic_authentication => [email, password]})

    rescue OpenURI::HTTPError
      url = nil
    end
  end  
  my_communities.elements.each('*/entry') { |x|
    # Add it to the OPML
    $stderr.puts "Found " + x.elements['title'].text
    if x.elements['id'].text =~ /communityUuid=([^&]+)/
      uuid = Regexp.last_match(1)
    end
    body.add_element 'outline', {'title' => x.elements['title'].text,
      'xmlUrl' => 'https://w3.ibm.com/connections/news/atom/stories/public?source=communities&container=' + uuid
    }
  }
  # Set the URL to the next one
  url = nil
  if my_communities.elements['feed/link[@rel="next"]']
    url = my_communities.elements['feed/link[@rel="next"]'].attributes['href']
  end
  sleep 5
end
puts opml.to_s

If you want just discussion topics and replies, use this instead of the xmlUrl line above:

'xmlUrl' => base_url + 'community/forum?communityUuid=' + uuid
You can comment with Disqus or you can e-mail me at sacha@sachachua.com.