Add hot topics widget
This commit is contained in:
13
back/main.py
13
back/main.py
@@ -581,6 +581,19 @@ def get_post_info():
|
||||
return jsonify({"code": 1000, "data": data})
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
@app.route('/api/hot_topics', methods=['GET'])
|
||||
def get_hot_topics():
|
||||
try:
|
||||
rows = db.session.query(
|
||||
Hashtag.name,
|
||||
db.func.count(Hashtag.name).label('count')
|
||||
).group_by(Hashtag.name).order_by(db.func.count(Hashtag.name).desc()).limit(5).all()
|
||||
|
||||
data = [{"name": name, "count": int(count)} for name, count in rows]
|
||||
return jsonify({"code": 1000, "data": {"list": data}})
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
# --- 彩蛋 ---
|
||||
@app.route('/api/teapot', methods=['GET'])
|
||||
|
||||
Reference in New Issue
Block a user