Created
March 9, 2014 15:46
-
-
Save seanmtracey/9449716 to your computer and use it in GitHub Desktop.
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
import sys, os, json, urllib, urllib2, time | |
f = open('listedBuildings.json') | |
locations = json.loads(f.read()) | |
coordinates = [] | |
streets = [] | |
thisStreet = "" | |
for item in locations: | |
streetName = item["Name"].split(',')[0] | |
if streetName != thisStreet: | |
streets.append(item) | |
thisStreet = streetName | |
for line in streets: | |
firstBit = line["Name"].split(',') | |
q = {"q" : str(firstBit[0]) + ", Bournemouth"} | |
req = "http://nominatim.openstreetmap.org/search?" + urllib.urlencode(q) + "&format=json&limit=5" | |
nominatim = json.loads(urllib2.urlopen(req).read()) | |
# print nominatim | |
if len(nominatim) > 0: | |
coordinates.append({ | |
"latitude" : nominatim[0]["lat"], | |
"longitude" : nominatim[0]["lon"], | |
"name" : firstBit[0] | |
}) | |
print str(firstBit[0]) + " lat:" + nominatim[0]["lat"] + " long:" + nominatim[0]["lon"] + " found" | |
else: | |
print ">>>>> " + str(firstBit[0]) + " not found" | |
#print urllib2.urlopen(req).read() | |
w = open("coordinates.json", "w") | |
w.write(json.dumps(coordinates)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment