【问题标题】:Parse events from an .ics file in Python在 Python 中解析来自 .ics 文件的事件
【发布时间】:2013-01-26 02:50:20
【问题描述】:

基本上我的目标是我希望能够将 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

【问题讨论】:

    标签: python date calendar icalendar


    【解决方案1】:

    取决于“解析事件日期”的含义:您是否应该知道所有实例日期(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 属性值。

    【讨论】:

    • 很遗憾,这个描述已经过时了,如果有人想尝试那个,请查看已安装的 test.py 以了解它现在是如何工作的
    【解决方案2】:

    不妨试试:

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

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

    【讨论】:

    • 我收到了TypeError: <icalendar.prop.vDDDTypes object at 0x108745690> is not JSON serializable
    猜你喜欢
    • 2011-03-25
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 2012-10-31
    相关资源
    最近更新 更多