From 21782a05160bf2141803d9b3ba65e3d8f752e9f6 Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Tue, 6 Aug 2024 01:35:57 +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/api/remote_server.py | 20 ++++++++++++++++++++ pywxdump/db/dbMSG.py | 18 +++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pywxdump/api/remote_server.py b/pywxdump/api/remote_server.py index b121747..7c086d9 100644 --- a/pywxdump/api/remote_server.py +++ b/pywxdump/api/remote_server.py @@ -470,6 +470,26 @@ def get_date_count(): return ReJson(0, date_count) +@rs_api.route('/api/rs/top_talker_count', methods=["GET", 'POST']) +def get_top_talker_count(): + """ + 获取最多聊天的人 + :return: + """ + if request.method not in ["GET", "POST"]: + return ReJson(1003, msg="Unsupported method") + rq_data = request.json if request.method == "POST" else request.args + word = rq_data.get("wxid", "") + start_time = rq_data.get("start_time", 0) + end_time = rq_data.get("end_time", 0) + + my_wxid = get_conf(g.caf, g.at, "last") + if not my_wxid: return ReJson(1001, body="my_wxid is required") + db_config = get_conf(g.caf, my_wxid, "db_config") + date_count = DBHandler(db_config).get_top_talker_count(top=10, start_time=start_time, end_time=end_time) + return ReJson(0, date_count) + + @rs_api.route('/api/rs/wordcloud', methods=["GET", 'POST']) @error9999 def wordcloud(): diff --git a/pywxdump/db/dbMSG.py b/pywxdump/db/dbMSG.py index 17eb2bd..426a95b 100644 --- a/pywxdump/db/dbMSG.py +++ b/pywxdump/db/dbMSG.py @@ -295,11 +295,16 @@ class MsgHandler(DatabaseBase): """ 获取每日聊天记录数量,包括发送者数量、接收者数量和总数。 """ - if start_time and end_time and isinstance(start_time, str) \ - and isinstance(end_time, str) and start_time.isdigit() and end_time.isdigit(): + if isinstance(start_time, str) and start_time.isdigit(): start_time = int(start_time) + if isinstance(end_time, str) and end_time.isdigit(): end_time = int(end_time) + # If either start_time or end_time is not an integer, set both to 0 + if not (isinstance(start_time, int) and isinstance(end_time, int)): + start_time = 0 + end_time = 0 + params = () sql_wxid = "AND StrTalker = ? " if wxid else "" @@ -336,13 +341,16 @@ class MsgHandler(DatabaseBase): """ 获取聊天记录数量最多的联系人,他们聊天记录数量 """ - if start_time and end_time and isinstance(start_time, str) \ - and isinstance(end_time, str) and start_time.isdigit() and end_time.isdigit(): + if isinstance(start_time, str) and start_time.isdigit(): start_time = int(start_time) + if isinstance(end_time, str) and end_time.isdigit(): end_time = int(end_time) - if start_time <= 0 or end_time <= 0: + + # If either start_time or end_time is not an integer, set both to 0 + if not (isinstance(start_time, int) and isinstance(end_time, int)): start_time = 0 end_time = 0 + sql_time = f"AND CreateTime BETWEEN {start_time} AND {end_time} " if start_time and end_time else "" sql = ( "SELECT StrTalker, COUNT(*) AS count,"