我正在尝试使用多个事件解析一个Feed,它只返回一个项目
ics = urllib.urlopen("https://www.google.com/calendar/ical/pcolalug%40gmail.com/public/basic.ics").read()
events = []
components = vobject.readComponents(ics)
for event in components:
to_zone = tz.gettz('America/Chicago')
date = event.vevent.dtstart.value.astimezone(to_zone)
description = event.vevent.description.value
events.append({
'start': date.strftime(DATE_FORMAT),
'description': description if description else 'No Description',
})
return {'events': events[:10]}
我做错了什么?
答案 0 :(得分:2)
切换到使用icalendar而不是vobject,它的效果要好得多。
ics = urllib.urlopen("https://www.google.com/calendar/ical/pcolalug%40gmail.com/public/basic.ics").read()
events = []
cal = Calendar.from_string(ics)
for event in cal.walk('vevent'):
to_zone = tz.gettz('America/Chicago')
date = event.get('dtstart').dt.astimezone(to_zone)
description = event.get('description')
events.append({
'start': date.strftime(DATE_FORMAT),
'description': description if description else 'No Description',
})
return {'events': events[:10]}