-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
36 lines (31 loc) · 926 Bytes
/
preprocess.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
import json
import re
import geopy
import os
API_KEY = os.environ["GOOGLE_API_KEY"]
geocoder = geopy.GoogleV3(api_key=API_KEY)
projects = []
with open("data/projects.json") as f:
projects = json.load(f)
print "Loaded projects"
for p in projects:
title = p["title"]
address = None
if re.match("\d+ \w", title):
address = title
else:
match = re.search("\((\d+.+)\)", title)
if match:
address = match.group(1)
if address:
p["address"] = address
print "Geocoding: " + address
location = geocoder.geocode(address + ", Mountain View, CA")
if location:
p["location"] = (location.latitude, location.longitude)
else:
print "Error geocoding: " + address
else:
print "Address not found for: ", title
with open("data/projects.json", "w") as f:
json.dump(projects, f, sort_keys=True, indent=4)