Add hot topics widget

This commit is contained in:
LeonspaceX
2026-01-30 15:50:20 +08:00
parent d787785660
commit c30803f073
4 changed files with 112 additions and 27 deletions

View File

@@ -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'])