解锁并提取Linux客户端微信数据库 (vibe coded)
at 46 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_html(wxid, outpath, db_config, my_wxid=""): 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 26 msgs, users = db.get_msgs(wxid, 0, chatCount + 1) 27 if len(msgs) == 0: 28 return False, "没有聊天记录" 29 30 data_js = ( 31 "localStorage.setItem('isUseLocalData', 't') // 't' : 'f' \n" 32 f"const local_msg_count = {chatCount}\n" 33 f"const local_mywxid = '{my_wxid}' \n" 34 f"const local_user_list = {json.dumps(users, ensure_ascii=False, indent=None )} \n" 35 f"const local_msg_list = {json.dumps(msgs, ensure_ascii=False, indent=None )} \n" 36 ) 37 38 save_path = os.path.join(outpath, f"data.js") 39 with open(save_path, "w", encoding="utf-8") as f: 40 f.write(data_js) 41 42 return True, f"导出成功: {outpath}" 43 44 45if __name__ == '__main__': 46 pass