-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (33 loc) · 1.07 KB
/
app.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
#!/usr/bin/python
from bottle import route, run
from bottle import template
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import json
engine=create_engine('mysql://root:[email protected]/stock?charset=utf8')
DB_session= sessionmaker(bind=engine)
@route('/')
@route('/home')
def home():
return template('template/home.html')
@route('/industry')
def get_industry():
session=DB_session()
result=session.execute('select c_name,count(*) as num from industry group by c_name order by num;').fetchall()
session.close()
data={'data':[]}
for i in result:
data['data'].append({'name':i[0],'value':i[1]})
json_str=json.dumps(data)
return json_str
@route('/area')
def get_area():
session=DB_session()
result=session.execute('select area,count(*) as num from area group by area order by num ;').fetchall()
session.close()
data={'data':[]}
for i in result:
data['data'].append({'name':i[0],'value':i[1]})
json_str=json.dumps(data)
return json_str
run(host='localhost', port=8080, debug=True)