3

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?

cleg
  • 4,862
  • 5
  • 35
  • 52

3 Answers3

3

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

Antonio Beamud
  • 2,281
  • 1
  • 15
  • 26
  • I've tried this lib, but it's only iCaledar-compatible and does not understand DTEND field and other extras. – cleg Nov 10 '10 at 16:06
  • for DTEND you can use until, as rrule pararameter. ¿What other extras do you need? – Antonio Beamud Nov 11 '10 at 12:47
  • 2
    @cleg: don't mistake iCalendar-the-standard (RFC 2445, now RFC 5545) with iCalendar-the-program. The calendar you show above is in iCalendar-the-format. – Ulrich Schwarz Nov 14 '10 at 16:11
  • This is where I wound up too. I did some simple parsing of the ical dtstart using strptime and then passed it to dateutil.rrule.rrulestr. – Julian Jun 10 '14 at 16:58
1

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.

GDR
  • 2,301
  • 1
  • 21
  • 26
  • Looking at that link you might think the library hasn't been updated in 4 years. More current versions can be found here: http://pypi.python.org/pypi/icalendar – mbarkhau Dec 13 '10 at 14:14
0

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)

Auberon Vacher
  • 4,655
  • 1
  • 24
  • 36