-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql-import.py
executable file
·47 lines (37 loc) · 1.05 KB
/
mysql-import.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='root', db='code66')
cur = conn.cursor()
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
data = go.go(go.live())
mc.set('latest', json.dumps(data))
for row in data:
row['lat'] = row['coords']['lat']
row['lon'] = row['coords']['lon']
q = """insert into locations (
date,
date_w3cdtf,
routeID,
busID,
lat,
lon,
speed,
heading
) values (
'%(msg_time)s',
'%(msg_time)s',
%(route_id)s,
%(bus_id)s,
%(lat)s,
%(lon)s,
%(speed)s,
%(heading)s)""" % row
#print q
cur.execute(q)
conn.commit()
cur.close()
conn.close()