Python solution to parse Google calendar's recurrencies

南楼画角 提交于 2019-12-21 05:44:19

问题


I'm trying to parse GCal's recurrence field. Usually, it looks like this:

DTSTART;TZID=Europe/Kiev:20101111T140000
DTEND;TZID=Europe/Kiev:20101111T150000
RRULE:FREQ=DAILY;UNTIL=20101112T120000Z
BEGIN:VTIMEZONE
TZID:Europe/Kiev
X-LIC-LOCATION:Europe/Kiev
BEGIN:DAYLIGHT
TZOFFSETFROM:+0200
TZOFFSETTO:+0300
TZNAME:EEST
DTSTART:19700329T030000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0300
TZOFFSETTO:+0200
TZNAME:EET
DTSTART:19701025T040000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE

I need to extract valuable for me part: event's DTSTART, DTEND, RRULE, and other iCaledar's field. Is there an existent solution for doing this?


回答1:


You can try the fantastic library python-dateutil (http://labix.org/python-dateutil).




回答2:


I'm using mxm's icalendar package:

http://codespeak.net/icalendar/

and I'm pretty sure it passes all ical fields to parsed objects. I'm not sure about reoccurence because I just don't use that in my app, but I would be surprised to find out it's not there.




回答3:


As I have a similar problem and could not find anything doing the job, I've just released on pypi a small project which will not only give you the DTSTART, DTEND, RRULE, RDATE, UID and SUMMARY values but will also given a specific time window return all the dates that fullfill the RRULE rules.

You can get it here: http://pypi.python.org/pypi/pyICSParser (please note I'm not at all a SW engineer so good coding practices compliance is poor and though I'll work on documentation it is still very early stage)



来源:https://stackoverflow.com/questions/4145508/python-solution-to-parse-google-calendars-recurrencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!