Reputation: 181
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.
Upvotes: 18
Views: 16963
Reputation: 14929
From the official documentation you can access the values of dtstart
and dtend
like this -
date = event.get('dtstart')
print date.to_ical()
they are icalendar.prop.vDDDTypes
objects. Neither string and nor do they have a intuitive __str__()
method, it seems. Hence you got that output.
Please read the documentation.
Upvotes: -3
Reputation: 51
A little late here, but if that helps: the API has been updated since (I did the same mistake // copy pasting another stackoverflow post) You need to use the method decoded() instead of get()
You can find the latest API reference to icalendar here : http://icalendar.readthedocs.io/en/latest/api.html
replace your call to get by decoded :
date = event.decoded('dtstart')
summery = event.decoded('summary')
It should work.
Upvotes: 5
Reputation: 2713
The objects representing dtstart
and dtend
have an attribute dt
which contains a standard datetime.datetime
object.
start = event.get('dtstart')
print(start.dt)
Upvotes: 42