Parsing iCal feed with Python using icalendar

user3163194 picture user3163194 · Jan 5, 2014 · Viewed 11.2k times · Source

I'm trying to parse a feed with multiple events using the icalendar lib in python.

'summary' , 'description' and so on works fine, but for 'dtstart' and 'dtend' it's returning me: icalendar.prop.vDDDTypes object at 0x101be62d0

def calTest():
    req = urllib2.Request('https://www.google.com/calendar/ical/XXXXXXXXXX/basic.ics')
    response = urllib2.urlopen(req)
    data = response.read()

    cal = Calendar.from_ical(data)

    for event in cal.walk('vevent'):

        date = event.get('dtstart')
        summery = event.get('summary')

        print str(date)
        print str(summery)

    return

What am I doing wrong? To use vobject its not a option, have to use the icalendar lib. Many thanks for any help for a python rookie.

Answer

t-8ch picture t-8ch · Jan 6, 2014

The objects representing dtstart and dtend have an attribute dt which contains a standard datetime.datetime object.

start = event.get('dtstart')
print(start.dt)