增加导出json方式
This commit is contained in:
parent
767b09c84e
commit
2078619916
@ -9,7 +9,7 @@ from .wx_info import BiasAddr, read_info, get_wechat_db, encrypt, batch_decrypt,
|
|||||||
from .wx_info import merge_copy_db, merge_msg_db, merge_media_msg_db, merge_db, decrypt_merge
|
from .wx_info import merge_copy_db, merge_msg_db, merge_media_msg_db, merge_db, decrypt_merge
|
||||||
from .analyzer.db_parsing import read_img_dat, read_emoji, decompress_CompressContent, read_audio_buf, read_audio, \
|
from .analyzer.db_parsing import read_img_dat, read_emoji, decompress_CompressContent, read_audio_buf, read_audio, \
|
||||||
parse_xml_string, read_BytesExtra
|
parse_xml_string, read_BytesExtra
|
||||||
from .analyzer import export_csv
|
from .analyzer import export_csv,export_json
|
||||||
from .ui import app_show_chat, get_user_list, export
|
from .ui import app_show_chat, get_user_list, export
|
||||||
from .server import start_falsk
|
from .server import start_falsk
|
||||||
|
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
# -------------------------------------------------------------------------------
|
# -------------------------------------------------------------------------------
|
||||||
from .db_parsing import read_img_dat, read_emoji, decompress_CompressContent, read_audio_buf, read_audio, \
|
from .db_parsing import read_img_dat, read_emoji, decompress_CompressContent, read_audio_buf, read_audio, \
|
||||||
parse_xml_string, read_BytesExtra
|
parse_xml_string, read_BytesExtra
|
||||||
from .export_chat import export_csv, get_contact_list, get_chatroom_list, get_msg_list, get_chat_count
|
from .export_chat import export_csv, get_contact_list, get_chatroom_list, get_msg_list, get_chat_count, export_json
|
||||||
from .utils import get_type_name, get_name_typeid
|
from .utils import get_type_name, get_name_typeid
|
||||||
|
@ -142,7 +142,8 @@ def get_msg_list(MSG_db_path, selected_talker="", start_index=0, page_size=500):
|
|||||||
voicelength = f"{voicelength:.2f}"
|
voicelength = f"{voicelength:.2f}"
|
||||||
content[
|
content[
|
||||||
"msg"] = f"语音时长:{voicelength}秒\n翻译结果:{transtext}" if transtext else f"语音时长:{voicelength}秒"
|
"msg"] = f"语音时长:{voicelength}秒\n翻译结果:{transtext}" if transtext else f"语音时长:{voicelength}秒"
|
||||||
content["src"] = os.path.join("audio", f"{StrTalker}", f"{CreateTime.replace(':', '-').replace(' ','_')}_{IsSender}_{MsgSvrID}.wav")
|
content["src"] = os.path.join("audio", f"{StrTalker}",
|
||||||
|
f"{CreateTime.replace(':', '-').replace(' ', '_')}_{IsSender}_{MsgSvrID}.wav")
|
||||||
elif type_id == (43, 0): # 视频
|
elif type_id == (43, 0): # 视频
|
||||||
BytesExtra = read_BytesExtra(BytesExtra)
|
BytesExtra = read_BytesExtra(BytesExtra)
|
||||||
BytesExtra = str(BytesExtra)
|
BytesExtra = str(BytesExtra)
|
||||||
@ -254,6 +255,27 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000):
|
|||||||
return True, f"导出成功: {outpath}"
|
return True, f"导出成功: {outpath}"
|
||||||
|
|
||||||
|
|
||||||
|
def export_json(username, outpath, MSG_ALL_db_path):
|
||||||
|
if not os.path.exists(outpath):
|
||||||
|
outpath = os.path.join(os.getcwd(), "export" + os.sep + username)
|
||||||
|
if not os.path.exists(outpath):
|
||||||
|
os.makedirs(outpath)
|
||||||
|
count = get_chat_count(MSG_ALL_db_path, username)
|
||||||
|
chatCount = count.get(username, 0)
|
||||||
|
if chatCount == 0:
|
||||||
|
return False, "没有聊天记录"
|
||||||
|
page_size = chatCount + 1
|
||||||
|
for i in range(0, chatCount, page_size):
|
||||||
|
start_index = i
|
||||||
|
data = get_msg_list(MSG_ALL_db_path, username, start_index, page_size)
|
||||||
|
if len(data) == 0:
|
||||||
|
return False, "没有聊天记录"
|
||||||
|
save_path = os.path.join(outpath, f"{username}_{i}_{i + page_size}.json")
|
||||||
|
with open(save_path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||||
|
return True, f"导出成功: {outpath}"
|
||||||
|
|
||||||
|
|
||||||
def export_html(user, outpath, MSG_ALL_db_path, MediaMSG_all_db_path, FileStorage_path, page_size=500):
|
def export_html(user, outpath, MSG_ALL_db_path, MediaMSG_all_db_path, FileStorage_path, page_size=500):
|
||||||
name_save = user.get("remark", user.get("nickname", user.get("username", "")))
|
name_save = user.get("remark", user.get("nickname", user.get("username", "")))
|
||||||
username = user.get("username", "")
|
username = user.get("username", "")
|
||||||
|
@ -335,15 +335,23 @@ def export():
|
|||||||
return ReJson(1002, body={"start_time": start_time, "end_time": end_time})
|
return ReJson(1002, body={"start_time": start_time, "end_time": end_time})
|
||||||
|
|
||||||
elif export_type == "csv":
|
elif export_type == "csv":
|
||||||
|
outpath = os.path.join(outpath, username)
|
||||||
if not os.path.exists(outpath):
|
if not os.path.exists(outpath):
|
||||||
os.makedirs(outpath)
|
os.makedirs(outpath)
|
||||||
code, ret = analyzer.export_csv(username, os.path.join(outpath, username), read_session(g.sf, "msg_path"))
|
code, ret = analyzer.export_csv(username, outpath, read_session(g.sf, "msg_path"))
|
||||||
if code:
|
if code:
|
||||||
return ReJson(0, ret)
|
return ReJson(0, ret)
|
||||||
else:
|
else:
|
||||||
return ReJson(2001, body=ret)
|
return ReJson(2001, body=ret)
|
||||||
elif export_type == "json":
|
elif export_type == "json":
|
||||||
pass
|
outpath = os.path.join(outpath, username)
|
||||||
|
if not os.path.exists(outpath):
|
||||||
|
os.makedirs(outpath)
|
||||||
|
code, ret = analyzer.export_json(username, outpath, read_session(g.sf, "msg_path"))
|
||||||
|
if code:
|
||||||
|
return ReJson(0, ret)
|
||||||
|
else:
|
||||||
|
return ReJson(2001, body=ret)
|
||||||
elif export_type == "html":
|
elif export_type == "html":
|
||||||
chat_type_tups = []
|
chat_type_tups = []
|
||||||
for ct in chat_type:
|
for ct in chat_type:
|
||||||
|
Loading…
Reference in New Issue
Block a user