diff --git a/pywxdump/api/local_server.py b/pywxdump/api/local_server.py index 812eeeb..6e9b56b 100644 --- a/pywxdump/api/local_server.py +++ b/pywxdump/api/local_server.py @@ -16,7 +16,7 @@ import pythoncom import pywxdump from flask import Flask, request, render_template, g, Blueprint, send_file, make_response, session -from pywxdump import get_core_db, all_merge_real_time_db +from pywxdump import get_core_db, all_merge_real_time_db, get_wx_db from pywxdump.api.rjson import ReJson, RqJson from pywxdump.api.utils import get_conf, get_conf_wxids, set_conf, error9999, gen_base64, validate_title, \ get_conf_local_wxid, ls_loger @@ -277,7 +277,9 @@ def merge(): out_path = request.json.get("outPath") if not out_path: return ReJson(1002) - rdata = merge_db(wxdb_path, out_path) + db_path = get_wx_db(wxdb_path) + # for i in db_path:print(i) + rdata = merge_db(db_path, out_path) return ReJson(0, str(rdata)) # END 这部分为专业工具的api *********************************************************************************************** diff --git a/pywxdump/api/remote_server.py b/pywxdump/api/remote_server.py index 0725e34..aacc2a2 100644 --- a/pywxdump/api/remote_server.py +++ b/pywxdump/api/remote_server.py @@ -147,7 +147,9 @@ def get_imgsrc(imgsrc): rc, fomt, md5, out_bytes = dat2img(original_img_path) if not rc: return ReJson(1001, body=original_img_path) - imgsavepath = os.path.join(str(img_tmp_path), img_path + "_" + ".".join([md5, fomt])) + imgsavepath = os.path.join(str(img_tmp_path), img_path + "_" + "".join([md5, fomt])) + if os.path.exists(imgsavepath): + return send_file(imgsavepath) if not os.path.exists(os.path.dirname(imgsavepath)): os.makedirs(os.path.dirname(imgsavepath)) with open(imgsavepath, "wb") as f: diff --git a/pywxdump/wx_core/merge_db.py b/pywxdump/wx_core/merge_db.py index 9171e58..32cc653 100644 --- a/pywxdump/wx_core/merge_db.py +++ b/pywxdump/wx_core/merge_db.py @@ -110,13 +110,12 @@ def merge_db(db_paths: List[dict], save_path: str = "merge.db", is_merge_data: b if isinstance(db_paths, list): # alias, file_path - databases = {f"MSG{i}": (db['db_path'], - db.get('de_path', db['db_path']) - ) for i, db in enumerate(db_paths) + databases = {f"dbi_{i}": (db['db_path'], + db.get('de_path', db['db_path']) + ) for i, db in enumerate(db_paths) } else: raise TypeError("db_paths 类型错误") - outdb = sqlite3.connect(save_path) is_sync_log = check_create_sync_log(outdb) @@ -134,15 +133,21 @@ def merge_db(db_paths: List[dict], save_path: str = "merge.db", is_merge_data: b sql_attach = f"ATTACH DATABASE '{de_path}' AS {alias}" out_cursor.execute(sql_attach) outdb.commit() - sql_query_tbl_name = f"SELECT name FROM {alias}.sqlite_master WHERE type='table' ORDER BY name;" + sql_query_tbl_name = f"SELECT tbl_name, sql FROM {alias}.sqlite_master WHERE type='table' ORDER BY tbl_name;" tables = execute_sql(outdb, sql_query_tbl_name) for table in tables: - table = table[0] + table, init_create_sql = table[0], table[1] + table = table if isinstance(table, str) else table.decode() + init_create_sql = init_create_sql if isinstance(init_create_sql, str) else init_create_sql.decode() if table == "sqlite_sequence": continue + if "CREATE TABLE".lower() not in str(init_create_sql).lower(): + continue # 获取表中的字段名 sql_query_columns = f"PRAGMA table_info({table})" columns = execute_sql(outdb, sql_query_columns) + if table == "ChatInfo" and len(columns) > 12: # bizChat中的ChatInfo表与MicroMsg中的ChatInfo表字段不同 + continue col_type = { (i[1] if isinstance(i[1], str) else i[1].decode(), i[2] if isinstance(i[2], str) else i[2].decode()) diff --git a/pywxdump/wx_core/wx_info.py b/pywxdump/wx_core/wx_info.py index 98b2ec4..ad7c334 100644 --- a/pywxdump/wx_core/wx_info.py +++ b/pywxdump/wx_core/wx_info.py @@ -389,10 +389,12 @@ def get_wx_db(msg_dir: str = None, db_types = None wxid_dirs = {} # wx用户目录 - for sub_dir in os.listdir(msg_dir): - if os.path.isdir(os.path.join(msg_dir, sub_dir)) and sub_dir not in ["All Users", "Applet", "WMPF"]: - wxid_dirs[os.path.basename(sub_dir)] = os.path.join(msg_dir, sub_dir) - + if "All Users"in os.listdir(msg_dir) or "Applet"in os.listdir(msg_dir) or "WMPF"in os.listdir(msg_dir): + for sub_dir in os.listdir(msg_dir): + if os.path.isdir(os.path.join(msg_dir, sub_dir)) and sub_dir not in ["All Users", "Applet", "WMPF"]: + wxid_dirs[os.path.basename(sub_dir)] = os.path.join(msg_dir, sub_dir) + else: + wxid_dirs[os.path.basename(msg_dir)] = msg_dir for wxid, wxid_dir in wxid_dirs.items(): if wxids and wxid not in wxids: # 如果指定wxid,则过滤掉其他wxid continue