调整入库内容,扩展一下其他内容
This commit is contained in:
@@ -2,6 +2,9 @@ import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import redis
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from wcferry import WxMsg
|
||||
|
||||
from message_summary.message_summary_4o import message_summary
|
||||
|
||||
import mysql.connector.pooling
|
||||
@@ -20,22 +23,24 @@ class MessageStorage:
|
||||
"""从连接池获取 Redis 连接"""
|
||||
return redis.Redis(connection_pool=self.redis_pool)
|
||||
|
||||
def archive_message(self, group_id, timestamp_str, sender, content, message_type, attachment_url=None):
|
||||
def archive_message(self, msg: WxMsg):
|
||||
# 连接到数据库
|
||||
connection = self.db_pool.get_connection()
|
||||
|
||||
try:
|
||||
now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
with connection.cursor() as cursor:
|
||||
# 插入消息信息
|
||||
sql = """
|
||||
INSERT INTO messages (group_id,timestamp, sender, content, message_type, attachment_url)
|
||||
INSERT INTO messages (group_id,timestamp, sender, content, message_type, attachment_url,message_id,message_xml,message_thumb)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
cursor.execute(sql, (group_id, timestamp_str, sender, content, message_type, attachment_url))
|
||||
cursor.execute(sql, (
|
||||
msg.roomid, now_time, msg.sender, msg.content, msg.type, msg.extra, msg.id, msg.xml, msg.thumb))
|
||||
|
||||
# 提交事务
|
||||
connection.commit()
|
||||
print(f"Archived:{timestamp_str}:{group_id}:{sender}: {content}")
|
||||
print(f"Archived:{now_time}:{msg.roomid}:{msg.sender}: {msg.content}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error archiving message: {e}")
|
||||
|
||||
3
robot.py
3
robot.py
@@ -286,8 +286,7 @@ class Robot(Job):
|
||||
|
||||
# 聊天记录入库动作:
|
||||
try:
|
||||
now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
self.message_storage.archive_message(msg.roomid, now_time, msg.sender, msg.content, msg.type, msg.extra)
|
||||
self.message_storage.archive_message(msg)
|
||||
# self.LOG.info(f"msg.xml:{msg.xml}")
|
||||
except Exception as e:
|
||||
self.LOG.error(f"archive_message error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user