-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmakeHtml.py
38 lines (29 loc) · 978 Bytes
/
makeHtml.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
#coding:utf-8
import MySQLdb
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def returnLocationList():
db = MySQLdb.connect("localhost","root","","putianhospital",charset='utf8' )
cursor = db.cursor()
cursor.execute("SELECT lat,lng,name FROM hospitallocation;")
data = cursor.fetchall()
db.close()
return data
def makeHtml():
file = open("html/test.html",'r')
html = file.read()
file.close()
header = html[:html.find("//PYTHONBRIDGEBEGIN")+len("//PYTHONBRIDGEBEGIN")]
footer = html[html.find("//PYTHONBRIDGEEND"):]
data = returnLocationList()
count = 0
script = "\n"
for lat,lng,name in data:
count += 1
script +=" var marker%s = new L.Marker(new L.latLng(%s, %s)); map.addLayer(marker%s);marker%s.bindPopup('%s');\n" %(count,lat,lng,count,count,name)
file = open("html/test.html",'w')
file.write(header+script+footer)
file.close()
if __name__ == '__main__':
makeHtml()