从Python中的.ics文件解析事件

2024-05-19 22:46:56 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我的目标是能够以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

Tags: 文件fromorgimportpypi信息http目标
2条回答

或许可以试试:

with Calendar.from_ical(open("work.ics")) as FileObj:
    for components in FileObj:
        print components

这应该打印文件中的每一行(未测试)。在

根据您所说的“parse events dates”:如果您是指能够知道所有实例的日期(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

注:免责声明-我写过/还在写这个模块,到目前为止它只处理日期属性值,而不处理日期时间属性值。在

相关问题 更多 >