We will illustrate how to create an icalendar object, and manipulate it.
First, we create an icalendar object with the needed properties (Version and Prodid) but without any component.
>>> from itools.ical.icalendar import icalendar
>>> cal = icalendar()
>>> from pprint import pprint
>>> pprint(cal.get_property_values())
{'PRODID': <itools.ical.icalendar.PropertyValue object at 0xa76cce8c>,
'VERSION': <itools.ical.icalendar.PropertyValue object at 0xa76cceec>}
You can see that the two needed properties have been automatically added.
We can add an other property to this icalendar object.
>>> from itools.ical.icalendar import PropertyValue
>>> cal.properties['METHOD'] = PropertyValue('PUBLISH')
We create a component of type ’VEVENT’ with some properties and add it to the icalendar object.
>>> from datetime import datetime
>>> properties = {}
>>> properties['SUMMARY'] = PropertyValue('Europython 2006')
>>> properties['DTSTART'] = PropertyValue(datetime(2006, 07, 03))
>>> properties['DTEND'] = PropertyValue(datetime(2006, 07, 05))
>>> uid = cal.add_component('VEVENT', **properties)
Now we add some new properties to this event, accessing it by its uid.
>>> properties = {'LOCATION': PropertyValue('Cern (Switzerland)')}
>>> cal.update_component(uid, **properties)
We can also add a more precised property which contains a parameter.
>>> parameters = {'MEMBER': ['MAILTO:DEV-GROUP@host.com']}
>>> value = PropertyValue('mailto:darwin@itaapy.com', **parameters)
>>> cal.update_component(uid, ATTENDEE=value)
>>>
>>> event = cal.get_component_by_uid(uid)
>>> pprint(event.get_property())
{'ATTENDEE': [<itools.ical.icalendar.PropertyValue object at 0xa7727e2c>],
'DTEND': <itools.ical.icalendar.PropertyValue object at 0xa7ad394c>,
'DTSTAMP': <itools.ical.icalendar.PropertyValue object at 0xb779a86c>,
'DTSTART': <itools.ical.icalendar.PropertyValue object at 0xa7727b2c>,
'LOCATION': <itools.ical.icalendar.PropertyValue object at 0xa7727dac>,
'SUMMARY': <itools.ical.icalendar.PropertyValue object at 0xa7727d8c>}
You can see that all properties have a PropertyValue except the ’ATTENDEE’ property which has a PropertyValue list, because this property can occur more than once inside of a component.
You can get the value(s) of a property by its name.
>>> summary = event.get_property_values('SUMMARY')
>>> print summary.value, summary.parameters
Europython 2006 {}
>>>
>>> attendees = event.get_property_values('ATTENDEE')
>>> print attendees
[<itools.ical.icalendar.PropertyValue object at 0xa7727e2c>]
>>> print attendees[0].value
mailto:darwin@itaapy.com
>>> print attendees[0].parameters
{'MEMBER': ['MAILTO:DEV-GROUP@host.com']}
>>>