forked from ptwobrussell/Recipes-for-Mining-Twitter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in a file to illustrate minimal geocoding legwork
- Loading branch information
ptwobrussell
authored and
Matthew Russell
committed
Apr 19, 2011
1 parent
9dd1eaf
commit 2fcf6f3
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |