From 9e2fa29e93e9b2552512422dd3f5316b0322967e Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Tue, 16 Jan 2024 19:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=81=8A=E5=A4=A9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=80=89=E6=8B=A9=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywxdump/api/api.py | 35 +++++++++++++++++++++++++++++++---- pywxdump/cli.py | 16 +++++++++++----- pywxdump/server.py | 2 +- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/pywxdump/api/api.py b/pywxdump/api/api.py index f57deec..9555688 100644 --- a/pywxdump/api/api.py +++ b/pywxdump/api/api.py @@ -12,6 +12,7 @@ from flask import Flask, request, render_template, g, Blueprint, send_file, make from pywxdump import analyzer, read_img_dat, read_audio from pywxdump.api.rjson import ReJson, RqJson from pywxdump import read_info, VERSION_LIST, batch_decrypt, BiasAddr, merge_db +import pywxdump # app = Flask(__name__, static_folder='../ui/web/dist', static_url_path='/') @@ -28,19 +29,26 @@ def init(): # g.msg_path = path # g.micro_path = path # g.media_path = path - # g.wxid_path = r"C:\Users\xaoyo\Documents\Tencent\WeChat Files\wxid_vzzcn5fevion22" + # g.wx_path = r"C:\Users\xaoyo\Documents\Tencent\WeChat Files\wxid_vzzcn5fevion22" # g.my_wxid = "wxid_vzzcn5fevion22" rdata = { "msg_path": "", "micro_path": "", "media_path": "", - "wxid_path": "", + "wx_path": "", "my_wxid": "", "is_init": False, } return ReJson(0, rdata) +@api.route('/api/version', methods=["GET", 'POST']) +def version(): + """ + 版本 + :return: + """ + return ReJson(0, pywxdump.__version__) @api.route('/api/contact_list', methods=["GET", 'POST']) def contact_list(): @@ -171,7 +179,7 @@ def get_img(): img_path = request.json.get("img_path", img_path) if not img_path: return ReJson(1002) - img_path_all = os.path.join(g.wxid_path, img_path) + img_path_all = os.path.join(g.wx_path, img_path) if os.path.exists(img_path_all): fomt, md5, out_bytes = read_img_dat(img_path_all) out_bytes = base64.b64encode(out_bytes).decode("utf-8") @@ -213,6 +221,11 @@ def export(): end_time = request.json.get("end_time") chat_type = request.json.get("chat_type") username = request.json.get("username") + + # 可选参数 + wx_path = request.json.get("wx_path", g.wx_path) + key = request.json.get("key", "") + if not export_type or not start_time or not end_time or not chat_type or not username: return ReJson(1002) chat_type_tups = [] @@ -228,7 +241,11 @@ def export(): if not os.path.exists(outpath): os.makedirs(outpath) - if export_type == "csv": + if export_type == "endb": + pass + elif export_type == "dedb": + pass + elif export_type == "csv": # 导出聊天记录 outpath = os.path.join(outpath, "csv") if not os.path.exists(outpath): @@ -236,6 +253,16 @@ def export(): code, ret = analyzer.export_csv(username, outpath, g.msg_path) if code: return ReJson(0, ret) + elif export_type == "json": + pass + elif export_type == "html": + pass + elif export_type == "pdf": + pass + elif export_type == "docx": + pass + else: + return ReJson(1002) return ReJson(0, "") diff --git a/pywxdump/cli.py b/pywxdump/cli.py index ed2d90c..7aba110 100644 --- a/pywxdump/cli.py +++ b/pywxdump/cli.py @@ -187,7 +187,7 @@ class MainShowChatRecords(): sb_decrypt.add_argument("-media", "--media_path", type=str, help="解密后的 MediaMSG.db 的路径", required=False, metavar="") - sb_decrypt.add_argument("-wid", "--wxid_path", type=str, + sb_decrypt.add_argument("-wid", "--wx_path", type=str, help="(可选)微信文件夹的路径(用于显示图片)", required=False, metavar="") sb_decrypt.add_argument("-myid", "--my_wxid", type=str, help="(可选)微信账号(本人微信id)", required=False, @@ -237,7 +237,8 @@ class MainShowChatRecords(): g.msg_path = args.msg_path g.micro_path = args.micro_path g.media_path = args.media_path - g.wxid_path = args.wxid_path + g.wx_path = args.wx_path + # g.key = args.key g.my_wxid = args.my_wxid g.tmp_path = os.path.join(os.getcwd(), "wxdump_tmp") # 临时文件夹,用于存放图片等 g.user_list = [] @@ -448,7 +449,7 @@ class MainAll(): args.msg_path = merge_save_path args.micro_path = merge_save_path args.media_path = merge_save_path - args.wxid_path = filePath + args.wx_path = filePath args.my_wxid = wxid args.online = online MainShowChatRecords().run(args) @@ -492,7 +493,7 @@ class MainUi(): def before_request(): g.msg_path = "" g.media_path = "" - g.wxid_path = "" + g.wx_path = "" g.my_wxid = "" g.tmp_path = os.path.join(os.getcwd(), "wxdump_tmp") # 临时文件夹,用于存放图片等 g.user_list = [] @@ -601,11 +602,16 @@ def console_run(): sb_all = main_all.init_parses(subparsers) modes[main_all.mode] = main_all + # 添加 'ui' 子命令解析器 + main_ui = MainUi() + sb_ui = main_ui.init_parses(subparsers) + modes[main_ui.mode] = main_ui + # 检查是否需要显示帮助信息 if len(sys.argv) == 1: sys.argv.append('all') elif len(sys.argv) == 2 and sys.argv[1] in modes.keys() and sys.argv[1] not in [main_all.mode, main_wx_info.mode, - main_wx_db_path.mode]: + main_wx_db_path.mode, main_ui.mode]: sys.argv.append('-h') args = parser.parse_args() # 解析命令行参数 diff --git a/pywxdump/server.py b/pywxdump/server.py index 6e8daa9..ae67758 100644 --- a/pywxdump/server.py +++ b/pywxdump/server.py @@ -23,7 +23,7 @@ def before_request(): g.msg_path = path g.micro_path = path g.media_path = path - g.wxid_path = r"*****" + g.wx_path = r"*****" g.my_wxid = "******" g.tmp_path = "dist" # 临时文件夹,用于存放图片等 g.user_list = []