Parsing your OPML for Touch and iPhone WebClip icons

Admittedly this will impact a very minor number of you out there, but I've been enjoying my newfound iPhone 1.1.3 capabilities, specifically in terms of fun new icons I can toss on my iPhone's desktop for a quick link to a website somewhere.

I started looking around, trying to see which one of the sites I normally frequent have super-special iPhone/iPod Touch icons around (like this fantastic site). It's a bit of a pain to do it all one at a time, so I looked at my feed reader.

NetNewsWire has an OPML export option, and I'm sure other readers do, too. I figured, hey, let's just try to see if I can parse that export to see which of my subscribed feeds have WebClips. It's a bit of a hack job since I only wanted to spend 10-15 minutes working on it, but it works decently for what it needs to do (and I had some help which shaved a few minutes off of the process).

require 'rubygems'
require 'hpricot' 

def valid_url?(url)
  uri = URI.parse(url)
  http_conn = Net::HTTP.new(uri.host, uri.port)
  resp, data = http_conn.head("/apple-touch-icon.png" , nil)
  resp.code == "200"
end

filename = ARGV.first

doc = open(filename) { |f| Hpricot(f) } 

(doc/"outline[@htmlurl]").each do |item| 
  url = item.attributes['htmlurl'] 
  puts url if valid_url?(url)
end

Nothing really groundbreaking here- just toss that in a file and then pass it the name of your OPML file, presuming they're both in the same directory. It'll then trawl through your subscriptions and spit out any domains that have WebClip icons. So, type something like

ruby webclip.rb subscriptions.opml

This also assumes Hpricot is installed

sudo gem install hpricot

Hooray. iPhone home screen icons.

Comments

The first thing I bought at my new job was an ipod touch to watch battlestar galactica on the commute to work. Then I got pissed off it wasn't an iphone and I couldn't check my email anywhere, but then I realized Hoboken has 40,000 young, stupid residents in 1 square mile, which means as many unsecured routers, so it is kind of like having an iphone. I think that makes me a bad person.

How's CMU?

Respond

Markdown is enabled on comments.