基本上,我的目标是我希望能够将 ics 文件作为输入,并能够解析出日期的事件,然后从每个事件中分解其中的信息。我一直试图用 http://pypi.python.org/pypi/icalendar 来解决这个问题
这是我目前了解到的情况。
from icalendar import Calendar, Event
cal = Calendar.from_ical(open('Work.ics','rb').read())
for component in cal.walk():
print component
最佳答案
取决于“解析事件日期”的含义:如果您的意思是能够了解所有实例日期(RRULE、RDATE、EXDATE),您也可以尝试 pyICSParser a ics events enumerator ,列出事件实例:
mycal = icalendar.ics()
mycal.local_load("work.ics")
dates = mycal.get_event_instances(start,end)
#dates will contain the json with all explicit dates of the events spec'ed by the iCalendar file
PS:免责声明 - 我编写/仍在编写此模块,到目前为止它仅处理 DATE 而不是 DATE-TIME 属性值。
关于python - 在 Python 中解析 .ics 文件中的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14533364/