fix 合并数据库,以及部分专业工具的显示问题
This commit is contained in:
parent
512c2ae6d4
commit
32a702acc3
@ -16,7 +16,7 @@ import pythoncom
|
|||||||
import pywxdump
|
import pywxdump
|
||||||
|
|
||||||
from flask import Flask, request, render_template, g, Blueprint, send_file, make_response, session
|
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.rjson import ReJson, RqJson
|
||||||
from pywxdump.api.utils import get_conf, get_conf_wxids, set_conf, error9999, gen_base64, validate_title, \
|
from pywxdump.api.utils import get_conf, get_conf_wxids, set_conf, error9999, gen_base64, validate_title, \
|
||||||
get_conf_local_wxid, ls_loger
|
get_conf_local_wxid, ls_loger
|
||||||
@ -277,7 +277,9 @@ def merge():
|
|||||||
out_path = request.json.get("outPath")
|
out_path = request.json.get("outPath")
|
||||||
if not out_path:
|
if not out_path:
|
||||||
return ReJson(1002)
|
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))
|
return ReJson(0, str(rdata))
|
||||||
|
|
||||||
# END 这部分为专业工具的api ***********************************************************************************************
|
# END 这部分为专业工具的api ***********************************************************************************************
|
||||||
|
@ -147,7 +147,9 @@ def get_imgsrc(imgsrc):
|
|||||||
rc, fomt, md5, out_bytes = dat2img(original_img_path)
|
rc, fomt, md5, out_bytes = dat2img(original_img_path)
|
||||||
if not rc:
|
if not rc:
|
||||||
return ReJson(1001, body=original_img_path)
|
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)):
|
if not os.path.exists(os.path.dirname(imgsavepath)):
|
||||||
os.makedirs(os.path.dirname(imgsavepath))
|
os.makedirs(os.path.dirname(imgsavepath))
|
||||||
with open(imgsavepath, "wb") as f:
|
with open(imgsavepath, "wb") as f:
|
||||||
|
@ -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):
|
if isinstance(db_paths, list):
|
||||||
# alias, file_path
|
# alias, file_path
|
||||||
databases = {f"MSG{i}": (db['db_path'],
|
databases = {f"dbi_{i}": (db['db_path'],
|
||||||
db.get('de_path', db['db_path'])
|
db.get('de_path', db['db_path'])
|
||||||
) for i, db in enumerate(db_paths)
|
) for i, db in enumerate(db_paths)
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
raise TypeError("db_paths 类型错误")
|
raise TypeError("db_paths 类型错误")
|
||||||
|
|
||||||
outdb = sqlite3.connect(save_path)
|
outdb = sqlite3.connect(save_path)
|
||||||
|
|
||||||
is_sync_log = check_create_sync_log(outdb)
|
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}"
|
sql_attach = f"ATTACH DATABASE '{de_path}' AS {alias}"
|
||||||
out_cursor.execute(sql_attach)
|
out_cursor.execute(sql_attach)
|
||||||
outdb.commit()
|
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)
|
tables = execute_sql(outdb, sql_query_tbl_name)
|
||||||
for table in tables:
|
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":
|
if table == "sqlite_sequence":
|
||||||
continue
|
continue
|
||||||
|
if "CREATE TABLE".lower() not in str(init_create_sql).lower():
|
||||||
|
continue
|
||||||
# 获取表中的字段名
|
# 获取表中的字段名
|
||||||
sql_query_columns = f"PRAGMA table_info({table})"
|
sql_query_columns = f"PRAGMA table_info({table})"
|
||||||
columns = execute_sql(outdb, sql_query_columns)
|
columns = execute_sql(outdb, sql_query_columns)
|
||||||
|
if table == "ChatInfo" and len(columns) > 12: # bizChat中的ChatInfo表与MicroMsg中的ChatInfo表字段不同
|
||||||
|
continue
|
||||||
col_type = {
|
col_type = {
|
||||||
(i[1] if isinstance(i[1], str) else i[1].decode(),
|
(i[1] if isinstance(i[1], str) else i[1].decode(),
|
||||||
i[2] if isinstance(i[2], str) else i[2].decode())
|
i[2] if isinstance(i[2], str) else i[2].decode())
|
||||||
|
@ -389,10 +389,12 @@ def get_wx_db(msg_dir: str = None,
|
|||||||
db_types = None
|
db_types = None
|
||||||
|
|
||||||
wxid_dirs = {} # wx用户目录
|
wxid_dirs = {} # wx用户目录
|
||||||
for sub_dir in os.listdir(msg_dir):
|
if "All Users"in os.listdir(msg_dir) or "Applet"in os.listdir(msg_dir) or "WMPF"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"]:
|
for sub_dir in os.listdir(msg_dir):
|
||||||
wxid_dirs[os.path.basename(sub_dir)] = os.path.join(msg_dir, sub_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():
|
for wxid, wxid_dir in wxid_dirs.items():
|
||||||
if wxids and wxid not in wxids: # 如果指定wxid,则过滤掉其他wxid
|
if wxids and wxid not in wxids: # 如果指定wxid,则过滤掉其他wxid
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user