innoQ

Vladimir's Tech Blog


Aggregating iCal with a simple python script

June 26, 2007

My current solution is to use a universal iCal viewer of netvibes.com (one iCal source capable). Below is how it looks like:

netvibes_calendar.png

And here is a proxy script I have put on my web server, that aggregates multiple iCal sources.

"""
aggregates multiple google calendars (in iCal format) and returns them as http response
"""
import urllib
calendars = [
    ("vd", "http://www.google.com/calendar/ical/put_your_url1_here"),
    ("innoq", "http://www.google.com/calendar/ical/put_your_url2_here"),
]

def vdcal(req):
    res = ""
    is_first = True
    for cal_id, cal_url in calendars:
        content = urllib.urlopen(cal_url)
        begin_emitting = False
        for l in content:
            if l.startswith("BEGIN:VEVENT") or is_first:
                begin_emitting = True
            if begin_emitting and not l.startswith("END:VCALENDAR"):
                res += l
        is_first = False
    res += "END:VCALENDAR"
    return res

For the first calender I take both the header and the events. For the following calenders I only take the events itself (starting with “BEGIN:VEVENT”). It’s that easy!

Powered by Movable Type 3.31