群总结加入了49类型,即引用类型,作为群聊常用形式,需要包含在总结中来。
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import redis
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
from message_summary.message_summary_4o import message_summary
|
||||
|
||||
# 配置数据库连接
|
||||
@@ -75,25 +75,37 @@ def get_messages(group_id, all_contacts: dict):
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# 更新 Redis 存储的当前时间
|
||||
r.set(key, current_date)
|
||||
# r.set(key, current_date)
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
# 执行查询,获取最近 8 小时的消息
|
||||
query = """
|
||||
SELECT timestamp, sender, content
|
||||
SELECT timestamp, sender, content,message_type
|
||||
FROM messages
|
||||
WHERE timestamp >= %s AND message_type = 1 AND group_id = %s
|
||||
WHERE timestamp >= %s AND message_type in(1,49) AND group_id = %s
|
||||
"""
|
||||
cursor.execute(query, (last_summary_time, group_id))
|
||||
|
||||
# 构建最终的结果字符串
|
||||
# message_type 需要加入49类型,因为49是引用之后的发言。但是49是xml ,需要将content进行xml解析
|
||||
|
||||
result = []
|
||||
for row in cursor.fetchall():
|
||||
timestamp, sender, content = row
|
||||
timestamp, sender, content, message_type = row
|
||||
try:
|
||||
if message_type == "49":
|
||||
# 解析 XML 字符串
|
||||
root = ET.fromstring(content)
|
||||
# 提取 title 内容
|
||||
content = root.find('.//title').text
|
||||
|
||||
except Exception as e:
|
||||
print(f"message_type 49 error: {e}")
|
||||
sender_name = all_contacts.get(sender, sender) # 获取发送者的名字,若找不到则使用原 ID
|
||||
result.append(f"{timestamp},{sender_name},{content}")
|
||||
|
||||
result_str = "\n".join(result) # 将结果拼接为最终字符串
|
||||
print(result_str)
|
||||
return result_str
|
||||
|
||||
|
||||
@@ -107,4 +119,5 @@ if __name__ == "__main__":
|
||||
# attachment_url = "http://example.com/attachment.pdf" # 可以为None如果没有附件
|
||||
#
|
||||
# archive_message(group_id, timestamp_str, sender, content, message_type, attachment_url)
|
||||
# get_messages("45317011307@chatroom", {})
|
||||
message_summary(get_messages("45317011307@chatroom", {}))
|
||||
|
||||
Reference in New Issue
Block a user