使用 Python 和 vobject 解析具有多个事件的 iCal 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]}
我做错了什么?
I'm trying to parse a feed with multiple events and its only returning me one item
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]}
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改用icalendar而不是vobject,效果好多了。
Switched to using icalendar instead of vobject, it works a lot better.