加入组ID
This commit is contained in:
@@ -5,6 +5,7 @@ USE message_archive;
|
||||
|
||||
CREATE TABLE messages (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
group_id varchar(20) not null ,
|
||||
timestamp VARCHAR(20) NOT NULL,
|
||||
sender VARCHAR(255) NOT NULL,
|
||||
content TEXT NULL,
|
||||
|
||||
@@ -9,7 +9,7 @@ db_config = {
|
||||
}
|
||||
|
||||
|
||||
def archive_message(timestamp_str, sender, content, message_type, attachment_url=None):
|
||||
def archive_message(group_id, timestamp_str, sender, content, message_type, attachment_url=None):
|
||||
# 连接到数据库
|
||||
connection = pymysql.connect(**db_config)
|
||||
|
||||
@@ -17,10 +17,10 @@ def archive_message(timestamp_str, sender, content, message_type, attachment_url
|
||||
with connection.cursor() as cursor:
|
||||
# 插入消息信息
|
||||
sql = """
|
||||
INSERT INTO messages (timestamp, sender, content, message_type, attachment_url)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
INSERT INTO messages (group_id,timestamp, sender, content, message_type, attachment_url)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
cursor.execute(sql, (timestamp_str, sender, content, message_type, attachment_url))
|
||||
cursor.execute(sql, (group_id, timestamp_str, sender, content, message_type, attachment_url))
|
||||
|
||||
# 提交事务
|
||||
connection.commit()
|
||||
@@ -37,10 +37,11 @@ def archive_message(timestamp_str, sender, content, message_type, attachment_url
|
||||
|
||||
# 示例用法
|
||||
if __name__ == "__main__":
|
||||
group_id ='XXX@123123'
|
||||
timestamp_str = "2025-02-06 11:15:28"
|
||||
sender = "XXX"
|
||||
content = "This is a test message with a string timestamp."
|
||||
message_type = "text"
|
||||
attachment_url = "http://example.com/attachment.pdf" # 可以为None如果没有附件
|
||||
|
||||
archive_message(timestamp_str, sender, content, message_type, attachment_url)
|
||||
archive_message(group_id,timestamp_str, sender, content, message_type, attachment_url)
|
||||
|
||||
Reference in New Issue
Block a user