jspricke / python-remind

Python library to convert between Remind and iCalendar
GNU General Public License v3.0
13 stars 6 forks source link

ValueError in vevent parsing #2

Closed fabrepe closed 9 years ago

fabrepe commented 9 years ago

Hello,

At first, thanks for this useful tool. But for my part it is unusable. I would like to use the script to retrieve owncloud stored icals but I got the following error: "ValueError: astimezone() cannot be applied to a naive datetime".

All day events (no start/end hours provided) are not causing error.

Thanks you again for your work.

Here is the print of a vevent leading to the error


BEGIN:VCALENDAR VERSION:2.0 PRODID:ownCloud Calendar BEGIN:VEVENT CREATED;VALUE=DATE-TIME:20150413T092233Z UID:697c1d5049 LAST-MODIFIED;VALUE=DATE-TIME:20150413T092233Z DTSTAMP;VALUE=DATE-TIME:20150413T092233Z SUMMARY:toto DTSTART;VALUE=DATE-TIME;TZID=Europe/Berlin:20150415T000000 DTEND;VALUE=DATE-TIME;TZID=Europe/Berlin:20150415T000000 END:VEVENT END:VCALENDAR


Here is the stacktrace from ipython :


ValueError Traceback (most recent call last)

in () 2 vevent = rdict[uid] 3 vevent.load() ----> 4 rem.append(vevent.data) 5 /usr/local/lib/python2.7/dist-packages/remind.pyc in append(self, ical, filename) 379 380 with self._lock: --> 381 copen(filename, 'a', encoding='utf-8').write(self.to_reminders(readOne(ical))) 382 383 def remove(self, uid, filename=None): /usr/local/lib/python2.7/dist-packages/remind.pyc in to_reminders(self, ical, label, priority) 368 def to_reminders(self, ical, label=None, priority=None): 369 """Return Remind commands for all events of a iCalendar""" --> 370 reminders = [self.to_remind(vevent, label, priority) for vevent in ical.vevent_list] 371 return ''.join(reminders) 372 /usr/local/lib/python2.7/dist-packages/remind.pyc in to_remind(self, vevent, label, priority) 353 354 if isinstance(vevent.dtstart.value, datetime): --> 355 remind.append(vevent.dtstart.value.astimezone(self._localtz).strftime('AT %H:%M').replace(' 0', ' ')) 356 if duration.total_seconds() > 0: 357 remind.append('DURATION %d:%02d' % divmod(duration.total_seconds() / 60, 60)) ValueError: astimezone() cannot be applied to a naive datetime ---
jspricke commented 9 years ago

HI @fabrepe,

sorry for the late reply. You example is missing the timezone information for Berlin. Can you make sure it works if you use this instead?

BEGIN:VCALENDAR
VERSION:2.0
PRODID:ownCloud Calendar
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:STANDARD
DTSTART:20001029T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20000326T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20150413T092233Z
UID:697c1d5049
LAST-MODIFIED;VALUE=DATE-TIME:20150413T092233Z
DTSTAMP;VALUE=DATE-TIME:20150413T092233Z
SUMMARY:toto
DTSTART;VALUE=DATE-TIME;TZID=Europe/Berlin:20150415T000000
DTEND;VALUE=DATE-TIME;TZID=Europe/Berlin:20150415T000000
END:VEVENT
END:VCALENDAR

I will release a new version with a bugfix later today.

jspricke commented 9 years ago

I've release version 0.4.0 which includes this fix to pypi as well. Can you please test it? Thanks!

fabrepe commented 9 years ago

I apologize, i really had no time to check it. I am doing it with the new pip version (0.5.3).