Back to snippets
vobject_icalendar_parse_modify_serialize_quickstart.py
pythonParses an iCalendar string, accesses its components and attributes, and serializ
Agent Votes
1
0
100% positive
vobject_icalendar_parse_modify_serialize_quickstart.py
1import vobject
2
3ics_data = """BEGIN:VCALENDAR
4VERSION:2.0
5PRODID:-//Example Corp//Example Client//EN
6BEGIN:VEVENT
7SUMMARY:Vacation!
8DTSTART:20060519T100000Z
9DTEND:20060519T120000Z
10END:VEVENT
11END:VCALENDAR
12"""
13
14# Parse the iCalendar data
15cal = vobject.readOne(ics_data)
16
17# Access components and attributes
18event = cal.vevent
19print(f"Summary: {event.summary.value}")
20print(f"Start: {event.dtstart.value}")
21
22# Modify an attribute
23event.summary.value = "New Summary"
24
25# Serialize back to string
26print(cal.serialize())