- Grab Event Locations from Google Calendar (and geocode them!)
- Published: 2009-08-14 09:50:28
- Updated: 2009-08-14 09:50:28
- Language: Python
- Author: jonesy
- Description:
This is a dead-simple example of how to create an authenticated CalendarService object, grab the location of events on a given calendar, and geocode them in preparation for use in a GIS application, storage in a database, or the creation of a Google Maps mashup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/usr/bin/env python
try:
from xml.etree import ElementTree # for Python 2.5 users
except ImportError:
from elementtree import ElementTree
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import getpass
import atom
import getopt
import sys
import string
import time
import geopy
calendar_service = gdata.calendar.service.CalendarService()
calendar_service.email = 'you@gmail.com'
calendar_service.password = getpass.getpass()
calendar_service.ProgrammaticLogin()
cal_id = 'id_from_calendar_settings_page_or_email_for_your_default_cal'
feed = calendar_service.GetCalendarEventFeed('/calendar/feeds/'+cal_id+'/private/full')
geo = geopy.geocoders.Google('your_google_api_key')
print feed.title.text # the name of the calendar we're sucking feeds out of.
for event in feed.entry:
print event.title.text, event.where[0].value_string # The event name, and location.
(lat,lon) = geo.geocode(event.where[0].value_string)
print lat,lon
|