Skip to content

Commit d0ee9fe

Browse files
authored
Create totogeocode.py
1 parent 3f64732 commit d0ee9fe

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: totogeocode.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sqlite3, urllib, json
2+
3+
# connect to database
4+
conn = sqlite3.connect('toto.sqlite')
5+
cur = conn.cursor()
6+
7+
googleapi='https://maps.googleapis.com/maps/api/geocode/json?address='
8+
query=cur.execute('SELECT postal_code FROM placeall WHERE scanned=0').fetchall()
9+
10+
11+
for i in query:
12+
for i in i:
13+
print i
14+
try:
15+
url=('{}{}').format(googleapi,i)
16+
html = urllib.urlopen(url).read()
17+
jsonP = json.loads(html)
18+
lat = jsonP['results'][0]['geometry']['location']['lat']
19+
long = jsonP['results'][0]['geometry']['location']['lng']
20+
cur.execute('UPDATE placeall SET latitude=?,longitude=?,scanned=? WHERE postal_code=?', (lat,long,1,i,))
21+
conn.commit()
22+
except:
23+
pass
24+
25+
print 'done'

0 commit comments

Comments
 (0)