Listing 2. dynamic-calendar.py, a program that generates a calendar in iCalendar format. #!/usr/bin/python # Grab the CGI module import cgi from iCalendar import Calendar, Event from datetime import datetime from iCalendar import UTC # timezone # Log any problems that we might have import cgitb cgitb.enable(display=0, logdir="/tmp") # Send a content-type header to the user's browser print "Content-type: text/calendar\n\n" # Create a calendar object cal = Calendar() # What product created the calendar? cal.add('prodid', '-//Python iCalendar 0.9.3//mxm.dk//') # Version 2.0 corresponds to RFC 2445 cal.add('version', '2.0') # Create one event event = Event() event.add('summary', 'ATF deadline') event.add('dtstart', datetime(2005,3,11,8,0,0,tzinfo=UTC())) event.add('dtend', datetime(2005,3,11,10,0,0,tzinfo=UTC())) event.add('dtstamp', datetime(2005,3,11,0,10,0,tzinfo=UTC())) event['uid'] = 'ATF20050311A@lerner.co.il' # Give this very high priority! event.add('priority', 5) # Add the event to the calendar cal.add_component(event) # Ask the calendar to render itself as an iCalendar # file, and return that file in an HTTP response! print cal.as_string()