Created
March 19, 2012 23:31
-
-
Save jmillikan/2128421 to your computer and use it in GitHub Desktop.
Autocomplete API establishment tests
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
Results for Dayton, OH | |
26 Tests, 0 Errors, 17/26 Matches (65%) | |
Match types: set([u'doctor', u'food', u'hospital', u'restaurant', u'health', u'lodging', u'establishment', u'university', u'point_of_interest']) | |
Non-match types: set([u'route', u'political', u'locality']) | |
Results for Roswell, NM | |
26 Tests, 0 Errors, 13/26 Matches (50%) | |
Match types: set([u'restaurant', u'food', u'hospital', u'health', u'point_of_interest', u'lodging', u'establishment', u'university', u'store']) | |
Non-match types: set([u'establishment', u'route', u'park']) | |
Results for Yonkers, NY | |
26 Tests, 0 Errors, 15/26 Matches (58%) | |
Match types: set([u'courthouse', u'restaurant', u'food', u'hospital', u'library', u'health', u'stadium', u'establishment', u'point_of_interest']) | |
Non-match types: set([u'doctor', u'university', u'locality', u'political', u'airport', u'dentist', u'health', u'establishment', u'route', u'point_of_interest']) | |
Results for Tipton, IN (rural) | |
26 Tests, 0 Errors, 18/26 Matches (69%) | |
Match types: set([u'bar', u'restaurant', u'food', u'establishment', u'university', u'library', u'stadium', u'car_repair', u'point_of_interest']) | |
Non-match types: set([u'establishment', u'colloquial_area', u'political', u'point_of_interest']) | |
Results for Madison, WI | |
26 Tests, 0 Errors, 20/26 Matches (77%) | |
Match types: set([u'liquor_store', u'hospital', u'health', u'point_of_interest', u'stadium', u'lodging', u'establishment', u'university', u'store']) | |
Non-match types: set([u'political', u'route', u'establishment', u'locality']) | |
Results for Bothell, WA | |
26 Tests, 0 Errors, 17/26 Matches (65%) | |
Match types: set([u'restaurant', u'food', u'university', u'pharmacy', u'health', u'store', u'stadium', u'lodging', u'establishment', u'point_of_interest']) |
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
#!/usr/bin/env python | |
# 'requests' in PyPI or https://github.com/kennethreitz/requests | |
import requests | |
import optparse | |
import json | |
optp = optparse.OptionParser() | |
optp.add_option('-k', '--api-key',default='YOUR_KEY_HERE') | |
optp.add_option('-v', '--verbose',default=False,action='store_true') | |
optp.add_option('-l', '--location') | |
optp.add_option('-d', '--description') | |
(options,args) = optp.parse_args() | |
test_count = 0 | |
match_count = 0 | |
error_count = 0 | |
match_types = set() | |
nonmatch_types = set() | |
def v(s): | |
if options.verbose: | |
print s | |
for arg in args: | |
auto_resp = requests.get( | |
'https://maps.googleapis.com/maps/api/place/autocomplete/json', | |
params = { | |
'location' : options.location, | |
'radius' : 10000, | |
'input' : arg, | |
'types' : 'establishment', | |
'sensor' : 'false', | |
'key' : options.api_key | |
}) | |
auto_results = json.loads(auto_resp.text) | |
if len(auto_results['predictions']) > 0: | |
test_count += 1 | |
res = auto_results['predictions'][0] | |
details_resp = requests.get( | |
'https://maps.googleapis.com/maps/api/place/details/json', | |
params = { | |
'key' : options.api_key, | |
'reference' : res['reference'], | |
'sensor' : 'false' | |
}) | |
details = json.loads(details_resp.text) | |
if details['status'] != 'OK': | |
v('ERROR') | |
error_count += 1 | |
continue | |
if details['result']['id'] != res['id']: | |
v('NON-MATCH') | |
v('| Autocomplete: %s (ID: %s)' % (res['description'], res['id'])) | |
v('| Details : %s (ID: %s)' % (details['result']['name'], details['result']['id'])) | |
for t in details['result']['types']: | |
nonmatch_types.add(t) | |
else: | |
match_count += 1 | |
v('MATCH') | |
for t in details['result']['types']: | |
match_types.add(t) | |
print 'Results for %s' % options.description | |
if test_count - error_count > 0: | |
print '%d Tests, %d Errors, %d/%d Matches (%.0f%%)' % (test_count, error_count, match_count, test_count - error_count, 100 * float(match_count) / float(test_count - error_count)) | |
else: | |
print '%d Tests, %d Errors' % (test_count, error_count) | |
print 'Match types: %s' % match_types | |
print 'Non-match types: %s' % nonmatch_types |
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
#!/usr/bin/env sh | |
KEY="-k $1" | |
./test.py $KEY -l 39.753849,-84.173010 {a..z} -d 'Dayton, OH' | |
./test.py $KEY -l 33.390969,-104.530663 {a..z} -d 'Roswell, NM' | |
./test.py $KEY -l 40.942751,-73.888705 {a..z} -d 'Yonkers, NY' | |
./test.py $KEY -l 40.286909,-86.073156 {a..z} -d 'Tipton, IN (rural)' | |
./test.py $KEY -l 43.122313,-89.332565 {a..z} -d 'Madison, WI' | |
./test.py $KEY -l 47.760474,-122.204974 {a..z} -d 'Bothell, WA' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment