From 136ff95a8991c00ddfb7676b50c77003acf0efd9 Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Tue, 6 Aug 2024 01:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E6=94=B6=E3=80=81?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E6=95=B0=E9=87=8F=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywxdump/db/dbMSG.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pywxdump/db/dbMSG.py b/pywxdump/db/dbMSG.py index ea4b099..2ab6011 100644 --- a/pywxdump/db/dbMSG.py +++ b/pywxdump/db/dbMSG.py @@ -293,20 +293,36 @@ class MsgHandler(DatabaseBase): @db_error def get_date_count(self, wxid=''): """ - 获取日聊天记录数量 + 获取每日聊天记录数量,包括发送者数量、接收者数量和总数。 """ - sql_base = ("SELECT strftime('%Y-%m-%d', CreateTime, 'unixepoch', 'localtime') as date, COUNT(*) " - "FROM MSG WHERE StrTalker not like '%chatroom%' ") + sql_base = ( + "SELECT strftime('%Y-%m-%d', CreateTime, 'unixepoch', 'localtime') AS date, " + " SUM(CASE WHEN IsSender = 1 THEN 1 ELSE 0 END) AS sender_count, " + " SUM(CASE WHEN IsSender = 0 THEN 1 ELSE 0 END) AS receiver_count, " + " COUNT(*) AS total_count " + "FROM MSG " + "WHERE StrTalker NOT LIKE '%chatroom%' " + ) params = () - sql_wxid = "AND StrTalker=? " if wxid else "" + sql_wxid = "AND StrTalker = ? " if wxid else "" params += (wxid,) if wxid else params sql = f"{sql_base} {sql_wxid} GROUP BY date ORDER BY date ASC;" result = self.execute(sql, params) + if not result: return {} - return {row[0]: row[1] for row in result} + # 将查询结果转换为字典 + result_dict = {} + for row in result: + date, sender_count, receiver_count, total_count = row + result_dict[date] = { + "sender_count": sender_count, + "receiver_count": receiver_count, + "total_count": total_count + } + return result_dict @db_error