import icalendar with open('mycalendar.ics') as f: cal_string = f.read() # parse the iCalendar string into a Calendar object cal = icalendar.Calendar.from_ical(cal_string) # print the number of events in the Calendar print(len(cal.walk('VEVENT')))
import requests import icalendar url = 'https://www.example.com/mycalendar.ics' # download the iCalendar string from the URL cal_string = requests.get(url).text # parse the iCalendar string into a Calendar object cal = icalendar.Calendar.from_ical(cal_string) # print the summary of the first event event = cal.walk('VEVENT')[0] print(event['SUMMARY'])In this example, the requests library is used to download an iCalendar string from a URL. The string is then parsed into a Calendar object and the summary of the first event is printed. Overall, the python icalendar library is a useful tool for working with iCalendar files. It provides an easy-to-use interface for parsing and generating iCalendar components in Python.