From 118bd104180310e93a1db3d53254021f77a6a6e7 Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Sun, 14 Jan 2024 20:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E8=81=8A=E5=A4=A9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywxdump/analyzer/export_chat.py | 1 - pywxdump/api/api.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pywxdump/analyzer/export_chat.py b/pywxdump/analyzer/export_chat.py index 0fec3c9..c1e275b 100644 --- a/pywxdump/analyzer/export_chat.py +++ b/pywxdump/analyzer/export_chat.py @@ -233,7 +233,6 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000): data = get_msg_list(MSG_ALL_db_path, username, start_index, page_size) if len(data) == 0: return False, "没有聊天记录" - break save_path = os.path.join(outpath, f"{username}_{i}_{i + page_size}.csv") with open(save_path, "w", encoding="utf-8", newline='') as f: csv_writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL) diff --git a/pywxdump/api/api.py b/pywxdump/api/api.py index 0bde353..3fa7cad 100644 --- a/pywxdump/api/api.py +++ b/pywxdump/api/api.py @@ -214,6 +214,21 @@ def export(): chat_type_tups += tup if not chat_type_tups: return ReJson(1002) + + # 导出路径 + outpath = os.path.join(g.tmp_path, "export") + if not os.path.exists(outpath): + os.makedirs(outpath) + + if export_type == "csv": + # 导出聊天记录 + outpath = os.path.join(outpath, "csv") + if not os.path.exists(outpath): + os.makedirs(outpath) + code, ret = analyzer.export_csv(username, outpath, g.msg_path) + if code: + return ReJson(0, ret) + return ReJson(0, "")