collective / icalendar

icalendar parser library for Python
https://icalendar.readthedocs.io/en/latest/
Other
958 stars 166 forks source link

Cannot decode 'TRIGGER' item #215

Open JSpiner opened 7 years ago

JSpiner commented 7 years ago

blow ics file, cannot decode 'TRIGGER' item.


BEGIN:VCALENDAR
PRODID:-//NHN Corp//Naver Calendar 1.0//KO
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Asia/Seoul
TZURL:http://tzurl.org/zoneinfo-outlook/Asia/Seoul
X-LIC-LOCATION:Asia/Seoul
BEGIN:STANDARD
TZOFFSETFROM:+0900
TZOFFSETTO:+0900
TZNAME:KST
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20110916T015234Z
LAST-MODIFIED:20120829T235500Z
DTSTAMP:20170221T080255Z
UID:testtesttesttest@naver.com
TRANSP:TRANSPARENT
STATUS:TENTATIVE
SEQUENCE:0
SUMMARY:mybirthday
DESCRIPTION:
DTSTART;VALUE=DATE:19920323
DTEND;VALUE=DATE:19920324
CLASS:PUBLIC
LOCATION:
PRIORITY:5
RRULE:FREQ=YEARLY;INTERVAL=1
X-NAVER-STICKER-ID:006
X-NAVER-STICKER-POS:0
X-NAVER-STICKER-DEFAULT-POS:1
X-NAVER-CATEGORY-ID:0
X-NAVER-ANNIVERSARY:TRUE
X-NAVER-SCHEDULE-DETAIL-VIEW-URL:https://caldav.test.test/test
X-NAVER-WRITER-ID:kkk1140
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER:-PT12H
DESCRIPTION:
END:VALARM
END:VEVENT
END:VCALENDAR

I'm trying to parse every 'VEVENT' data.


def parseICS(ics):
    dictResult = {}
    dictResult['VEVENT'] = {}
    print(ics)
    calendar = Calendar.from_ical(ics)
    for component in calendar.walk():
        if component.name == "VEVENT":
            for row in component.property_items():
                print(str(row) + " " + str(component.get(row[0])))
                if isinstance(row[1], icalendar.prop.vDDDTypes): 
                    result = component.decoded(row[0]) # <- error in here!
                else:
                    result = str(row[1])
            dictResult['VEVENT'][row[0]] = result
    return dictResult

below is my error

('TRIGGER', <icalendar.prop.vDDDTypes object at 0x7f0a45697a90>) None
Traceback (most recent call last):
  File "main.py", line 29, in <module>
    eventDataList = calendars[0].getCalendarData(eventList)
  File "/home/jspiner/soma/python-caldavclient/caldavclient/caldavclient.py", line 228, in getCalendarData
    eventData = response.find("propstat").find("prop").find("calendar-data").text()
  File "/home/jspiner/soma/python-caldavclient/caldavclient/caldavclient.py", line 304, in __init__
    self.eventData = util.parseICS(eventData)
  File "/home/jspiner/soma/python-caldavclient/caldavclient/util.py", line 50, in parseICS
    result = component.decoded(row[0])
  File "/home/jspiner/soma/python-caldavclient/env/lib/python3.5/site-packages/icalendar/cal.py", line 240, in decoded
    raise KeyError(name)
KeyError: 'TRIGGER'

I think it cannot decode TRIGGER vDDDTypes object.

natashamm commented 1 month ago

There is a problem with how the function (parseICS) is written and using decoded.

In this line when we get the error:

result = component.decoded(row[0]) # <- error in here!

component is an Event row[0] is Trigger (not a property in Event), so we would want there to be an error.

Edit: so this issue can be closed