解锁并提取Linux客户端微信数据库 (vibe coded)
at 43 lines 1.5 kB view raw
1# -*- coding: utf-8 -*-# 2# ------------------------------------------------------------------------------- 3# Name: exportCSV.py 4# Description: 5# Author: xaoyaoo 6# Date: 2024/04/20 7# ------------------------------------------------------------------------------- 8import json 9import os 10from wxdump_linux.db import DBHandler 11 12 13def export_json(wxid, outpath, db_config, my_wxid="", indent=4): 14 if not os.path.exists(outpath): 15 outpath = os.path.join(os.getcwd(), "export" + os.sep + wxid) 16 if not os.path.exists(outpath): 17 os.makedirs(outpath) 18 19 db = DBHandler(db_config, my_wxid) 20 21 count = db.get_msgs_count(wxid) 22 chatCount = count.get(wxid, 0) 23 if chatCount == 0: 24 return False, "没有聊天记录" 25 users = {} 26 page_size = chatCount + 1 27 for i in range(0, chatCount, page_size): 28 start_index = i 29 data, users_t = db.get_msgs(wxid, start_index, page_size) 30 users.update(users_t) 31 if len(data) == 0: 32 return False, "没有聊天记录" 33 34 save_path = os.path.join(outpath, f"{wxid}_{i}_{i + page_size}.json") 35 with open(save_path, "w", encoding="utf-8") as f: 36 json.dump(data, f, ensure_ascii=False, indent=indent) 37 with open(os.path.join(outpath, "users.json"), "w", encoding="utf-8") as f: 38 json.dump(users, f, ensure_ascii=False, indent=indent) 39 return True, f"导出成功: {outpath}" 40 41 42if __name__ == '__main__': 43 pass