Python solution to parse Google calendar's rec

2019-03-31 23:44发布

问题:

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)