So today I spend some time with finding the best calendar for my Gnome desktop. Lo and behold I ended up installing the old rainlendar lite, well known from my windows days. Simply put, I just didn’t find a different calendar which I liked that much, even though I would prefer an open source alternative with similar features.

That being said, the lite version of rainlendar doesn’t allow to import Google calendars, only calendar files from your desktop. But importing from Google Calendar is something I absolutely wanted so I put a quick hack together to make it happen (actually this blog made me come up with it) . Here is how to do it (you will need python and some scheduling program):

First thing you’ll need is to find out the private ical address of the Google calendars you want and put it into a file, I called mine  icals.txt ;) To find the address go to Google calendar, click on settings, click on calendars, click on the calendar you want (if you have several) , scroll all the way to the bottom where it says “Private Address” and then click on the green ICAL button. It will show you an address, copy that into your ical file. Put the name of the calendar in front of it, followed by a colon and a space. So my first entry in the file looks like this (all one line)
Paul: http://www.google.com/calendar/ical/paul.koerbitz%40googlemail.com/private-XXXXXXXXXXXXXXXXXXXXXXXXXXXX/basic.ics
Repeat this for all the calendars you want to show up in rainlendar.

Ok, now for the hacking:  create the following python script:

#!/usr/bin/env python
"""Downloads calendars in ical format.

Takes two arguments:
first	: location of file containing the ical URLs.
second: directory where the ical calendars should be saved"""

import os
import sys
import re
import urllib

icals = open(sys.argv[1])

for line in icals:
	nextical = re.search('(.*):\s+(.*)',line).groups()
	outfile = os.path.join(sys.argv[2],nextical[0]+".ics")
	urllib.urlretrieve(nextical[1],outfile)

and save it (I called mine get-icals.py). What this does is that it goes through the file with your ical urls, splits each line at the first colon (that’s why you should save them in the form name: http://….), gets each ical file from google, and saves them as name.ics in a path specified by the second argument given to the script. So you want to call it like so
get-icals.py /path/to/icals.txt /path/to/output/
or
python get-icals.py c:\whatever\whatever\icals.txt c:\bla\bla\
(I am guessing here, I don’t have Windows.).

Once you called the script, the calendar files from google should be in the directory you specified and you can import them in rainlendar (right click on it -> Options -> Calendars -> Add … -> locate the .ics files). Be sure to change the “Monitor changes” option to “Yes”, otherwise this exercise would be quite useless ;) . I also changed “Read only” to “Yes” to remind myself that this “syncing” is one-way only, from Google to rainlendar (if you want two way, you would have to get the pro version, I suppose).

Ok, now to actually keep rainlendar synced, you have basically two options. Either hook the python script to a scheduler (I used cron, I guess something else would work just as well) or create a launcher for the script and call it (click on it) whenever you want to sync. For cron I used (this is on Ubuntu – good post on cron here)
$sudo crontab -e
and entered
0 * * * * /home/paul/bin/get-icals.py /home/paul/.icals/icals.txt /home/paul/.icals/
which makes cron update the icals every 60 which is sufficient for my not so rapidly changing schedule ;) .

Ok, first post, took a lot longer than I thought, HTH!
cheers
Paul

Advertisement