From da7072b2c3468b4a52f576698cb855eb2440feb2 Mon Sep 17 00:00:00 2001 From: Zheng Huang Date: Wed, 22 May 2024 21:29:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E4=B8=8E=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加性能和查询选项 --- pywxdump/dbpreprocess/parsingMSG.py | 8 +++++++- pywxdump/dbpreprocess/parsingMicroMsg.py | 4 +++- pywxdump/wx_info/merge_db.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pywxdump/dbpreprocess/parsingMSG.py b/pywxdump/dbpreprocess/parsingMSG.py index 06282d2..b1a0b87 100644 --- a/pywxdump/dbpreprocess/parsingMSG.py +++ b/pywxdump/dbpreprocess/parsingMSG.py @@ -247,17 +247,23 @@ class ParsingMSG(DatabaseBase): "room_name": StrTalker, "content": content, "CreateTime": CreateTime, "id": id} return row_data - def msg_list(self, wxid="", start_index=0, page_size=500): + def msg_list(self, wxid="", start_index=0, page_size=500, msg_type: str = ""): if wxid: sql = ( "SELECT localId, IsSender, StrContent, StrTalker, Sequence, Type, SubType,CreateTime,MsgSvrID,DisplayContent,CompressContent,BytesExtra,ROW_NUMBER() OVER (ORDER BY CreateTime ASC) AS id " "FROM MSG WHERE StrTalker=? " "ORDER BY CreateTime ASC LIMIT ?,?") + if msg_type: + sql = sql.replace("ORDER BY CreateTime ASC LIMIT ?,?", + f"AND Type={msg_type} ORDER BY CreateTime ASC LIMIT ?,?") result1 = self.execute_sql(sql, (wxid, start_index, page_size)) else: sql = ( "SELECT localId, IsSender, StrContent, StrTalker, Sequence, Type, SubType,CreateTime,MsgSvrID,DisplayContent,CompressContent,BytesExtra,ROW_NUMBER() OVER (ORDER BY CreateTime ASC) AS id " "FROM MSG ORDER BY CreateTime ASC LIMIT ?,?") + if msg_type: + sql = sql.replace("ORDER BY CreateTime ASC LIMIT ?,?", + f"AND Type={msg_type} ORDER BY CreateTime ASC LIMIT ?,?") result1 = self.execute_sql(sql, (start_index, page_size)) if not result1: return [], [] diff --git a/pywxdump/dbpreprocess/parsingMicroMsg.py b/pywxdump/dbpreprocess/parsingMicroMsg.py index f4f453a..4cf9ca7 100644 --- a/pywxdump/dbpreprocess/parsingMicroMsg.py +++ b/pywxdump/dbpreprocess/parsingMicroMsg.py @@ -72,7 +72,7 @@ class ParsingMicroMsg(DatabaseBase): def user_list(self, word=None): """ 获取联系人列表 - :param MicroMsg_db_path: MicroMsg.db 文件路径 + :param word 查询关键字,可以是用户名、昵称、备注、描述,允许拼音 :return: 联系人列表 """ users = [] @@ -87,6 +87,8 @@ class ParsingMicroMsg(DatabaseBase): f"OR A.NickName LIKE '%{word}%' " f"OR A.Remark LIKE '%{word}%' " f"OR A.Alias LIKE '%{word}%' " + f"OR A.QuanPin LIKE LOWER('%{word}%') " + f"OR LOWER(A.PYInitial) LIKE LOWER('%{word}%') " # f"OR A.Reserved6 LIKE '%{word}%' " "ORDER BY A.NickName DESC;") result = self.execute_sql(sql) diff --git a/pywxdump/wx_info/merge_db.py b/pywxdump/wx_info/merge_db.py index 1dbdfbd..5cf63c7 100644 --- a/pywxdump/wx_info/merge_db.py +++ b/pywxdump/wx_info/merge_db.py @@ -299,7 +299,7 @@ def merge_db(db_paths, save_path="merge.db", CreateTime: int = 0, endCreateTime: return save_path -def decrypt_merge(wx_path, key, outpath="", CreateTime: int = 0, endCreateTime: int = 0) -> (bool, str): +def decrypt_merge(wx_path, key, outpath="", CreateTime: int = 0, endCreateTime: int = 0, db_type: list[str] = []) -> (bool, str): """ 解密合并数据库 msg.db, microMsg.db, media.db,注意:会删除原数据库 :param wx_path: 微信路径 eg: C:\*******\WeChat Files\wxid_********* @@ -319,7 +319,13 @@ def decrypt_merge(wx_path, key, outpath="", CreateTime: int = 0, endCreateTime: # 分割wx_path的文件名和父目录 msg_dir = os.path.dirname(wx_path) my_wxid = os.path.basename(wx_path) - db_type = ["MSG", "MediaMSG", "MicroMsg", "OpenIMContact", "OpenIMMedia", "OpenIMMsg", "Favorite"] + db_type_set: set[str] = {"MSG", "MediaMSG", "MicroMsg", "OpenIMContact", "OpenIMMedia", "OpenIMMsg", "Favorite"} + if len(db_type) == 0: + db_type = list(db_type_set) + else: + for i in db_type: + if i not in db_type_set: + return False, f"db_type参数错误, 可用选项 {db_type_set}" # 解密 code, wxdbpaths = get_core_db(wx_path, db_type) if not code: