문제

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?

도움이 되었습니까?

해결책

Switched to using icalendar instead of vobject, it works a lot better.

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]}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top