From 2fcf6f31176018a32449ba2bfa8103b68fa4d3f4 Mon Sep 17 00:00:00 2001 From: ptwobrussell Date: Tue, 19 Apr 2011 07:21:19 -0700 Subject: [PATCH] Adding in a file to illustrate minimal geocoding legwork --- etc/geocoding_pattern.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 etc/geocoding_pattern.py diff --git a/etc/geocoding_pattern.py b/etc/geocoding_pattern.py new file mode 100644 index 0000000..df426b2 --- /dev/null +++ b/etc/geocoding_pattern.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +# A simple pattern created to illustrate geocoding for Where 2.0 (2011) +# Get your Google Maps API Key from http://code.google.com/apis/maps/signup.html + +import geopy +GOOGLE_MAPS_API_KEY = '' +g = geopy.geocoders.Google(GOOGLE_MAPS_API_KEY) + + +transforms = [('Greater ', ''), + (' Area', ''), + ('San Francisco Bay', 'San Francisco')] # etc. + +locations = ['Greater Nashville Area', + 'San Francisco Bay'] # from LinkedIn data + +cache = {} +for location in locations: + if cache.has_key(location): # Preserve API calls + continue + + for transform in transforms: + results = g.geocode(location, exactly_one=False) + cache[location] = [r for r in results][0][1] + break + +import json +print json.dumps(cache, indent=2)