-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
44 lines (33 loc) · 1.02 KB
/
api.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
# encoding: utf-8
# author: gendseo
# date: 2019-10-12
# updated: 2019-10-16
from flask import render_template
from db import App, app
import service
'''
api 模块
提供可访问的 api 接口
'''
# 主页接口
# 返回主页模板
@app.route('/')
def index():
apps = App.query.order_by(App.rank.desc(), App.rank_num.desc(
), App.hot.desc(), App.comment.desc()).all()
return render_template('index.html', apps=apps)
# 评分统计接口
# 用于图表显示
@app.route('/count/ranks')
def ranks():
ranks = [i[0] for i in App.query.with_entities(App.rank).all()]
return service.count_rank(ranks)
# 评分和评分次数关系统计接口
# 用于图表显示
@app.route('/count/rank_rank_num')
def ranks_rank_num():
apps = App.query.order_by(App.rank.desc(), App.rank_num.desc(), App.hot.desc(
), App.comment.desc()).with_entities(App.name, App.rank_num, App.rank).all()
return {'data': [i[1:] for i in apps], 'name': [i[0] for i in apps]}
if __name__ == '__main__':
app.run(debug=True)