Fetch publicly available google calendar data with python

I tried accessing the google data api with python - that api seems either overly complicated or just not suited for just grabbing events from a public google calendar.

This worked for me:

  1. find out ical address (subscribe to the calendar, other calendars->arrow down->calendar settings)
  2. install icalendar

Then this is possible:

PYTHON:
  1. from icalendar import Calendar
  2. import urllib
  3. ics = urllib.urlopen('http://www.google.com/calendar/ical/fchppllvcaupb6fgguigobkfj4@group.calendar.google.com/public/basic.ics').read()
  4. ical=Calendar.from_string(ics)
  5. for vevent in ical.subcomponents:
  6.   if vevent.name != "VEVENT":
  7.     continue
  8.   title = str(vevent.get('SUMMARY'))
  9.   description = str(vevent.get('DESCRIPTION'))
  10.   location = str(vevent.get('LOCATION'))
  11.   start = vevent.get('DTSTART').dt             # a datetime
  12.   end = vevent.get('DTEND').dt                 # a datetime

Leave a Reply