1

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?

sontek
  • 12,111
  • 12
  • 49
  • 61

1 Answers1

2

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]}
sontek
  • 12,111
  • 12
  • 49
  • 61
  • icalendar is not available as package in linux. It is verymuch possible with vobject. – Khurshid Alam May 11 '17 at 16:25
  • Thats not true, you just "pip install icalendar" and it works. Its pure python and has no C extensions so it works on all platforms. https://pypi.python.org/pypi/icalendar/3.11.4 – sontek May 12 '17 at 17:00