The icalendar package looks beautiful.
For example, to write a file:
from icalendar import Calendar, Event from datetime import datetime from pytz import UTC
Tadaaaa, you get this file:
BEGIN:VCALENDAR PRODID:-//My calendar product//mxm.dk// VERSION:2.0 BEGIN:VEVENT DTEND;VALUE=DATE:20050404T100000Z DTSTAMP;VALUE=DATE:20050404T001000Z DTSTART;VALUE=DATE:20050404T080000Z PRIORITY:5 SUMMARY:Python meeting about calendaring UID:20050115T101010/27346262376@mxm.dk END:VEVENT END:VCALENDAR
But what lies in this file?
g = open('example.ics','rb') gcal = Calendar.from_ical(g.read()) for component in gcal.walk(): print component.name g.close()
You can easily see this:
>>> VCALENDAR VEVENT >>>
How about parsing event data:
g = open('example.ics','rb') gcal = Calendar.from_ical(g.read()) for component in gcal.walk(): if component.name == "VEVENT": print(component.get('summary')) print(component.get('dtstart')) print(component.get('dtend')) print(component.get('dtstamp')) g.close()
Now you get:
>>> Python meeting about calendaring 20050404T080000Z 20050404T100000Z 20050404T001000Z >>>
Wok Aug 04 '10 at 18:17 2010-08-04 18:17
source share