[Vobject] how to add multiple events to a calendar ?

Jeffrey Harris jeffrey at osafoundation.org
Thu Jul 12 17:48:02 CDT 2007


Hi Didier,

> I'm trying to create a calendar from scratch with vobject. I can add
> one event, but I don't understand how to have multiple ones. Do you
> have an example to gives me for this feature ?

Sure, here you go:

import vobject, datetime

cal = vobject.iCalendar()
ev1 = cal.add('vevent')
ev1.add('dtstart').value = datetime.datetime.now()
ev1.add('summary').value = "First event"
ev2 = cal.add('vevent')
ev2.add('dtstart').value = datetime.datetime.now()
ev2.add('summary').value = "Second event"
print [ev.dtstart for ev in cal.vevent_list]

[<DTSTART{}2007-07-12 15:45:47.651089>,
 <DTSTART{}2007-07-12 15:46:05.367089>]

print cal.serialize()

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//PYVOBJECT//NONSGML Version 1//EN
BEGIN:VEVENT
UID:20070712T224732Z-89665 at Wind
DTSTART:20070712T154547
SUMMARY:First event
END:VEVENT
BEGIN:VEVENT
UID:20070712T224732Z-38563 at Wind
DTSTART:20070712T154605
SUMMARY:Second event
END:VEVENT
END:VCALENDAR

Sincerely,
Jeffrey


More information about the VObject mailing list