-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_fusion.py
39 lines (34 loc) · 1.29 KB
/
update_fusion.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
import ftclient as ft
import urllib2
from xml.etree.ElementTree import parse
def getGeocode(address):
add_list=address.split()
add_html='+'.join(add_list)
maps_request="http://maps.googleapis.com/maps/api/geocode/xml?address="+\
add_html+"&sensor=true"
#maps_request="http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true"
#maps_request="http://maps.googleapis.com/maps/api/geocode/json?address=205+Wilmington+Ave,+TORONTO,+ONTARIO,+CANADA&sensor=true"
req = urllib2.Request(url=maps_request)
etree = parse(urllib2.urlopen(req)).getroot()
loc = etree.find('result/geometry/location')
lat = loc.findtext('lat')
lng = loc.findtext('lng')
return (lat,lng)
def getIDAddresses(tableid):
client = ft.FTClient("")
query = "select ID,ADDRESS from "\
+str(self.tableid)
header_data = client.runGetQuery(query)
data = header_data.partition('\n')[2]
rows = data.split('\n')
id_addr = [ (r.partition(',')[0],r.partition(',')[2]) for r in rows ]
return id_addr
def addlatlng():
tableid = 2334172
id_addresses = getIDAddresses(tableid)
client = ft.FTClient("")
for id,address in id_addresses:
lat,lng = getGeocode(address)
query = "update "+str(tableid)+" set "+\
"LATITUDE="+str(lat)+", LONGITUDE="+\
str(lng)+" where ID="+str(id)