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,"