-
Notifications
You must be signed in to change notification settings - Fork 0
/
walkscore.py
34 lines (28 loc) · 1.42 KB
/
walkscore.py
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
32
33
34
from geopy import Nominatim
from geopy import MapQuest
import json
import urllib
MAPQUEST_API_KEY = 'M4GKnzAc6Pyz418vyJyXlmSu4PqSsOFR'
def get_location(location_str):
locator = Nominatim(user_agent='myGeocoder')
location = locator.geocode(location_str)
if not location:
locator = MapQuest(MAPQUEST_API_KEY)
location = locator.geocode(location_str)
return location
def walkscore(location_str):
location = get_location(location_str)
website = 'https://api.walkscore.com/score?format=json&lat=' + str(location.latitude) + '&lon=' + str(location.longitude) +'&transit=1&bike=1&wsapikey=b1c9cb0cbfab72947704a84addb4a9e9'
with urllib.request.urlopen(website) as url:
data = json.loads(url.read().decode())
print('walkscore is ' + str(data['walkscore']) + '\n')
print('transit score is ' + str(data['transit']['score']) + '\n')
print('bike score is ' + str(data['bike']['score']) + '\n')
def get_scores(location_str):
location = get_location(location_str)
website = 'https://api.walkscore.com/score?format=json&lat=' + str(location.latitude) + '&lon=' + str(location.longitude) +'&transit=1&bike=1&wsapikey=b1c9cb0cbfab72947704a84addb4a9e9'
with urllib.request.urlopen(website) as url:
data = json.loads(url.read().decode())
return str(data['walkscore']), str(data['transit']['score']), str(data['bike']['score'])
# var = input('Enter Address: ')
# walkscore(var)