Friday, February 10, 2012

plan2ics

This is a quick note about a small Python script I wrote to translate my home calendar into the iCalendar format.

I use an "old" calendar system called plan (sometimes "netplan" which is the server program, and easier to find on Google). It is fast, simple, and I have been using it since 1997, so I don't see any reason to change.

Then I bought an Android phone... which loves to sync with the Google Calendar, and can be convinced to sync with most iCal sources, but has no support for my system.

So what I decided to not do was to write an Android content provider to connect to my netplan server and get the calendar directly. This is the most elegant solution, but I didn't have the time to learn how to do it. (But when I do have time, I should look at the aCal app to see what needs doing...)

Instead I wrote a conversion script. plan2ics is on Launchpad.net, and it takes the netplan file as input and creates an iCal output. I allow the iCal file to be served by a webserver, then tell Google Calendar to import the calendar from an external URL. Once Google has it, the calendar gets synced down to my Android phone.
Oh, and I can also use the calendar URL for email clients like Evolution or Thunderbird.

So it works, but are there any problems?

Well yes, thanks for asking.

First, it is a READ-ONLY solution. So no updating the entries on the web or phone and expecting them to appear in netplan - for this I need to make my own client (see above).

Second, I'm not handling the UID for events properly. At the moment I have a fudge that will break when events are moved around, then I get duplicates in the calendar. To fix this I need to borrow a trick from some old tools to sync netplan with Palm Pilots, and that is to write the UID back into the netplan file as a comment, then reuse the UID in the next export.