I had what I thought was a simple task. I wanted to get a group calendar that I was putting together in Google out into a list that I could print out to pass around to the *ahem* more tactilely oriented among us.

Google Calendar does print and agenda format which is okay except for the fact that it adds in the person who created the event and the calendar that the event came from. This is great if you want to know all the information, but if you are just trying to print off a quick list for people to read, they often don’t want to look through multiple pages of repetitive text. Also, think of the tree-folk.

So I thought, I have desktop programs that can read a calendar, surely they will have a view that corresponds to my needs. I looked at iCalendar for OSX and I happened to have a copy of Entourage (first time using it, I guess it is like Outlook light?), but neither of these applications met my needs. Entourage teased me on to the point of getting me to a list that I thought looked good, but then would not let me print it.

So then I thought to myself, “self”, I said, because I always refer to myself in the third person, the second person sounds so accusatory, “you’re a programmer, how hard could this problem be?”

So I took a look at the Ruby libraries and I immediately found http://icalendar.rubyforge.org/. So I installed it

gem install icalendar

and created this little ruby program to export a CSV for my easy printing needs.

#!/usr/bin/env ruby

require 'rubygems'
require 'icalendar'
require 'date'

ARGV.each do |filename|
  file = File.open(filename)
  cals = Icalendar.parse(file)

  cals.each do |calendar|
    calendar.events.each do |event|
      puts """ + event.dtstart.strftime("%Y-%m-%d %H:%M") + "","" + event.dtend.strftime("%Y-%m-%d %H:%M") + "","" + event.summary + "","" + event.location + """

I hope this helps someone out there. I was surprised how quickly I managed to get that up and running, it took me longer to write the blog post than it did to write the code.