{"contents":"# -*- coding: utf-8 -*-#\n# -------------------------------------------------------------------------------\n# Name: exportCSV.py\n# Description: \n# Author: xaoyaoo\n# Date: 2024/04/20\n# -------------------------------------------------------------------------------\nimport json\nimport os\nfrom wxdump_linux.db import DBHandler\n\n\ndef export_json(wxid, outpath, db_config, my_wxid=\"我\", indent=4):\n if not os.path.exists(outpath):\n outpath = os.path.join(os.getcwd(), \"export\" + os.sep + wxid)\n if not os.path.exists(outpath):\n os.makedirs(outpath)\n\n db = DBHandler(db_config, my_wxid)\n\n count = db.get_msgs_count(wxid)\n chatCount = count.get(wxid, 0)\n if chatCount == 0:\n return False, \"没有聊天记录\"\n users = {}\n page_size = chatCount + 1\n for i in range(0, chatCount, page_size):\n start_index = i\n data, users_t = db.get_msgs(wxid, start_index, page_size)\n users.update(users_t)\n if len(data) == 0:\n return False, \"没有聊天记录\"\n\n save_path = os.path.join(outpath, f\"{wxid}_{i}_{i + page_size}.json\")\n with open(save_path, \"w\", encoding=\"utf-8\") as f:\n json.dump(data, f, ensure_ascii=False, indent=indent)\n with open(os.path.join(outpath, \"users.json\"), \"w\", encoding=\"utf-8\") as f:\n json.dump(users, f, ensure_ascii=False, indent=indent)\n return True, f\"导出成功: {outpath}\"\n\n\nif __name__ == '__main__':\n pass\n","is_binary":false,"path":"wxdump_linux/api/export/export_json.py","ref":""}