-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_js_event_data.py
47 lines (38 loc) · 935 Bytes
/
gen_js_event_data.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
event_types=[
'SUSPICIOUS CIRCUMSTANCES',
'TRAFFIC RELATED CALLS',
'FALSE ALARMS',
'DISTURBANCES',
'BURGLARY',
'CAR PROWL',
'AUTO THEFTS',
'NUISANCE, MISCHIEF',
'OTHER PROPERTY',
'FRAUD CALLS',
'PROPERTY DAMAGE'
]
query="select latitude, longitude from seattle_crime where event_clearance_group = %s"
conn = MySQLdb.connect(host= "192.168.59.103", user="student", passwd="secret", db="crime")
ccount=0
f=open("jsdata/out.js", "wb")
for event in event_types:
try:
cursor = conn.cursor()
cursor.execute(query, (event,))
rows = cursor.fetchall()
usedata=[]
for r in rows:
usedata.append("new google.maps.LatLng(%s,%s)" % (r[0], r[1]))
f.write("var data%s=[\n" % ccount)
f.write(",".join(usedata))
f.write("];\n\n")
except Exception, ex:
print ex
finally:
cursor.close()
ccount +=1
f.close()
conn.close()