-
Notifications
You must be signed in to change notification settings - Fork 1
/
geocode.py
46 lines (38 loc) · 1.06 KB
/
geocode.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
35
36
37
38
39
40
41
42
43
44
45
46
from geopy.geocoders import GoogleV3
import time
geolocator = GoogleV3()
with open('schools_zero.txt') as schools_file:
schools = schools_file.read().strip().split('\n')
resources = []
for school in schools:
print school
time.sleep(1)
try:
address, (latitude, longitude) = geolocator.geocode(school)
except:
print "[ERR] FAILED TO GET LOCATION FOR ", school
else:
item = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
longitude,
latitude
]
},
"properties": {
"marker-color": "#3F3040",
"marker-symbol": "circle",
"name": school[:-3],
"address": address,
}
}
resources.append(item)
geo = {
"type": "FeatureCollection",
"features": resources
}
import json
with open("schools_zero.json", 'w') as json_file:
json_file.write(json.dumps(geo, indent=4, sort_keys=True))