加入美图网提取功能
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# 制作UI进行群管理,群功能管理,不使用指令完成。
|
||||
@@ -0,0 +1,60 @@
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
|
||||
import os
|
||||
|
||||
from group_auto.group_auto_invite import add_mapping, del_mapping, get_first_group_id, get_group_ids
|
||||
from ui.messages_list import get_total_messages, get_messages
|
||||
|
||||
# 设置 Flask 实例化时指定模板文件夹路径
|
||||
app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), '..', 'templates'))
|
||||
|
||||
|
||||
# 主菜单页面
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
# Redis 操作页面
|
||||
@app.route('/redis_operations', methods=['GET', 'POST'])
|
||||
def redis_operations():
|
||||
if request.method == 'POST':
|
||||
key = request.form.get('key')
|
||||
group_id = request.form.get('group_id')
|
||||
action = request.form.get('action')
|
||||
|
||||
result = ''
|
||||
if action == 'add':
|
||||
result = add_mapping(key, group_id)
|
||||
elif action == 'del':
|
||||
result = del_mapping(key, group_id)
|
||||
elif action == 'get':
|
||||
result = get_group_ids(key)
|
||||
elif action == 'get_first':
|
||||
result = get_first_group_id(key)
|
||||
|
||||
return render_template('group_auto_invite_ui.html', result=result)
|
||||
|
||||
return render_template('group_auto_invite_ui.html', result='')
|
||||
|
||||
|
||||
# 显示消息列表(分页)
|
||||
@app.route('/messages', methods=['GET'])
|
||||
def messages():
|
||||
page = int(request.args.get('page', 1)) # 获取当前页,默认为第一页
|
||||
per_page = 10 # 每页显示10条数据
|
||||
messages = get_messages(page, per_page) # 获取指定页的数据
|
||||
total = get_total_messages() # 获取总的消息数量
|
||||
total_pages = (total // per_page) + (1 if total % per_page > 0 else 0) # 总页数
|
||||
|
||||
# 分页控制,确保当前页数在有效范围内
|
||||
if page > total_pages:
|
||||
page = total_pages
|
||||
if page < 1:
|
||||
page = 1
|
||||
|
||||
return render_template('message_list.html', messages=messages, page=page, total_pages=total_pages)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
@@ -0,0 +1,42 @@
|
||||
import pymysql
|
||||
|
||||
# MySQL 配置
|
||||
db_config = {
|
||||
'host': '192.168.2.32',
|
||||
'user': 'root',
|
||||
'password': 'lw123456',
|
||||
'database': 'message_archive'
|
||||
}
|
||||
|
||||
|
||||
# 获取消息列表,按时间倒序
|
||||
def get_messages(page=1, per_page=10):
|
||||
try:
|
||||
connection = pymysql.connect(**db_config)
|
||||
with connection.cursor() as cursor:
|
||||
offset = (page - 1) * per_page
|
||||
cursor.execute(
|
||||
"SELECT id, group_id, timestamp, sender, content FROM messages ORDER BY timestamp DESC LIMIT %s OFFSET %s",
|
||||
(per_page, offset))
|
||||
messages = cursor.fetchall()
|
||||
return messages
|
||||
except pymysql.MySQLError as e:
|
||||
print(f"数据库查询失败: {e}")
|
||||
return []
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
# 获取消息总数
|
||||
def get_total_messages():
|
||||
try:
|
||||
connection = pymysql.connect(**db_config)
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SELECT COUNT(*) FROM messages")
|
||||
total = cursor.fetchone()[0]
|
||||
return total
|
||||
except pymysql.MySQLError as e:
|
||||
print(f"数据库查询失败: {e}")
|
||||
return 0
|
||||
finally:
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user