The return of the blogroll

Posted by Toby Wed, 13 Aug 2008 15:03:00 GMT

I’ve bought the blogroll back since it disappeared during the upgrade. It’s now generated from my google reader opml feed which I export and run though some ruby which means it’s going to be up-to-date more frequently.

Here is the code that takes the opml and outputs the html fragment:

#!/usr/bin/ruby

require 'rexml/document'
require 'pp.rb'

class FeedData
  attr_accessor :name, :url, :category

  def initialize( name, url, category )
    ( @name, @url, @category ) = name, url, category
  end
end

class FeedDataList
  def initialize()
    @array = Array::new
  end

  def add( name, url, category )
    tmpFeed = FeedData::new( name, url, category )
    @array.push( tmpFeed )
  end

  def eachCategory
    catArray = Array::new
    @array.each do |feed|
      if !catArray.member?( feed.category ) then
        catArray.push( feed.category )
      end
    end

    catArray.sort.each do |result|
      yield result
    end
  end

  def eachItemInCategory( category )
    @array.each do |feed|
      if feed.category == category then
        yield feed
      end
    end
  end
end

def parse_opml( opml_node, feeds, parents_names=[] )
  opml_node.elements.each('outline') do |element|
    if element.elements.size != 0 then
      feeds = parse_opml( element, feeds, parents_names + [ element.attributes[ 'text' ] ] )
    end
    if element.attributes['xmlUrl'] then
      feeds.add( element.attributes['title'], element.attributes['htmlUrl'], parents_names.last )
    end
  end

  return feeds
end

opml = REXML::Document.new( STDIN )
feeds = FeedDataList::new
feeds = parse_opml( opml.elements['opml/body'], feeds )

feeds.eachCategory do |category|
  print "<br /><strong>#{category}</strong> "
  feeds.eachItemInCategory( category ) do |item|
    print "<a href=\"#{item.url}\">#{item.name}</a> "
  end
  print "\n"
end

To make it work:

$ ./opml2html.rb < 

I got the inspiration for the recursive opml parsing code from the Dekstop blog, so thanks are due to them!

Twitter to facebook status ruby script

Posted by Toby Fri, 13 Jul 2007 10:50:00 GMT

UPDATE 2007-09-30: You can now make the twitter facebook application update your status, so this is now redundant!

UPDATE 2007-09-09 (Cribbed from Christian’s site as I couldn’t put it any better): It is with great disappointment that I must make this announcement. Facebook has requested that I remove the code from my website. They have also contacted everyone else who has found my code and publicly mentioned that they are using it.

I am saddened at this turn of events because the idea behind the code was to extend Facebook’s current service and fill in the gap that their API had. The API still does not provide a means for updating ones status.

I’ve been wanting to update my facebook status with my twitterings for some time now. Unfortunately facebook do not provide an API for setting the status so I have been thwarted. Until now. Yesterday I accidentally found Christian Flickinger’s blog entry where he has found a way to update facebook status using php. At the end of his blog he writes:

Anyone with some experience could easily use the above code to check Twitter and (if updated) push to Facebook. Happy mashing!

I know how the twitter api works and I’m a big fan of ruby so I thought I would pick up the gauntlet and hack up a quick ruby script to do just that.

You’ll need to install the json and curb gems for it to work. Then copy and paste the below code into a file called fbTwit.rb in a suitable place on your unix box (it writes state down so you may want it in it’s own directory), edit the variables so that they are correct for your accounts, run it by hand to check it works for you and then set it to run every (say) 10 minutes via cron with something like the following in your crontab:

00,10,20,30,40,50 * * * * cd [directory]; ./fbTwit.rb 2>&1 > /dev/null

# Code removed at the request of facebook.

The quality of the code probably isn’t that great: it only took a short time to write, but it works (for me).

[2007-08-01] Yesterday this stopped working, along with the SSL login for m.facebook.com. I have changed it to use the http login which still works, although whether you want your password sent in the clear is up to you.

TCSOTD 2007-01-05

Posted by Toby Fri, 05 Jan 2007 06:27:00 GMT