群总结加入了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", {}))
|
||||
|
||||
@@ -22,7 +22,7 @@ def message_summary(content):
|
||||
【基础要求】
|
||||
|
||||
总结风格:采用轻松幽默的口吻,加入适量的网络流行语和emoji(如👍/🎉等),让总结更有趣。
|
||||
时间范围:[自动识别日期]的群聊记录。
|
||||
时间范围:[自动识别最新日期]的群聊记录。
|
||||
|
||||
【结构要求】:
|
||||
⭐ 创意标题(10字内,带emoji)
|
||||
@@ -50,7 +50,7 @@ def message_summary(content):
|
||||
自动生成趣味头衔(如“段子王”、“知识达人”、“活跃分子”等)。
|
||||
|
||||
【输出模板】
|
||||
「[群名]-[日期]群聊总结」
|
||||
「[群名]の[最新日期]群聊总结」
|
||||
|
||||
📊 今日数据快报:
|
||||
- 共诞生[消息数]条信息
|
||||
@@ -85,7 +85,7 @@ def message_summary(content):
|
||||
📊 今日数据快报:
|
||||
- 共诞生428条信息
|
||||
- 最活跃时段:20:00-21:00(153条/小时)
|
||||
- 聊天时段:18:30 - 22:00
|
||||
- 聊天时段:2025-02-20 18:30:10 - 2025-02-20 22:00:39
|
||||
|
||||
🌌 话题总结:
|
||||
1️⃣ 【暗黑料理实验室】⭐️⭐️⭐️⭐️⭐️
|
||||
|
||||
Reference in New Issue
Block a user