-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_locations.py
executable file
·50 lines (37 loc) · 1.02 KB
/
update_locations.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
47
48
49
#!/usr/bin/python
from geopy import geocoders
import logging
from config import *
import sqlite3
import time
# Connect to db
conn = sqlite3.connect(database)
c = conn.cursor()
# start logging
logger = logging.getLogger('main.update_locations')
# Store response of query
res = c.execute('''
SELECT
upper(s.location_city),
upper(s.location_state)
FROM signatures as s
LEFT OUTER JOIN locations as l
ON l.location_city LIKE s.location_city
AND l.location_state LIKE s.location_state
WHERE l.loc_id IS NULL
GROUP BY upper(s.location_city), upper(s.location_state)
''')
# @TODO
#while row is not None:
# locations.append(row)
locations = []
for row in c:
locations.append(row)
for loc in locations:
insert_values = "(null, :city, :state)"
loc_dict = {"city": loc[0],
"state": loc[1]}
c.execute("INSERT INTO locations VALUES " + insert_values, loc_dict)
logger.info("Inserting... city: " + unicode(loc_dict["city"]) + " state: " + unicode(loc_dict["state"]))
conn.commit()
c.close()