pythonicalendarvobject

Parsing iCal feed with multiple events with Python and vobject


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?


Solution

  • 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]}