-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql-import-stops.py
executable file
·47 lines (36 loc) · 1.11 KB
/
mysql-import-stops.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
#!/usr/bin/env python
import json
import MySQLdb
import memcache
import go
if __name__ == '__main__':
conn = MySQLdb.connect('localhost', user='app', passwd='6,$S{1MOL$6_"5lft6', db='code66')
cur = conn.cursor()
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
data = go.get_stops()
#print json.dumps(data)
mc.set('stops', json.dumps(data))
for row in data:
#q_exists = """SELECT stopID FROM stops WHERE stopID = '%s'""" % row['id']
#if cur.execute(q_exists) > 0:
# continue
row['lat'] = row['coords']['lat']
row['lon'] = row['coords']['lon']
q = """insert into stops (
stopID,
lat,
lon,
name,
serves
) values (
%(id)s,
%(lat)s,
%(lon)s,
'%(name)s',
'%(serves)s')
""" % row
#print q
cur.execute(q)
conn.commit()
cur.close()
conn.close()