add export html
This commit is contained in:
parent
36fcb2ac44
commit
81832a2a99
4
.gitignore
vendored
4
.gitignore
vendored
@ -26,4 +26,6 @@ node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
*.local
|
||||
/pywxdump/ui/web/*
|
||||
/pywxdump/ui/web/assets/*
|
||||
|
@ -25,7 +25,7 @@ from pywxdump.api.utils import get_conf, get_conf_wxids, set_conf, error9999, ge
|
||||
from pywxdump import get_wx_info, WX_OFFS, batch_decrypt, BiasAddr, merge_db, decrypt_merge, merge_real_time_db
|
||||
|
||||
from pywxdump.db import DBHandler, download_file, dat2img
|
||||
from pywxdump.db.export import export_csv, export_json
|
||||
from pywxdump.db.export import export_csv, export_json, export_html
|
||||
|
||||
# app = Flask(__name__, static_folder='../ui/web/dist', static_url_path='/')
|
||||
|
||||
@ -449,6 +449,40 @@ def get_export_json():
|
||||
return ReJson(2001, body=ret)
|
||||
|
||||
|
||||
@rs_api.route('/api/rs/export_html', methods=["GET", 'POST'])
|
||||
def get_export_html():
|
||||
"""
|
||||
导出json
|
||||
:return:
|
||||
"""
|
||||
my_wxid = get_conf(g.caf, g.at, "last")
|
||||
if not my_wxid: return ReJson(1001, body="my_wxid is required")
|
||||
db_config = get_conf(g.caf, my_wxid, "db_config")
|
||||
|
||||
wxid = request.json.get("wxid")
|
||||
if not wxid:
|
||||
return ReJson(1002, body=f"username is required: {wxid}")
|
||||
|
||||
html_outpath = os.path.join(g.work_path, "export", my_wxid, "html")
|
||||
if not os.path.exists(html_outpath):
|
||||
os.makedirs(html_outpath)
|
||||
assert isinstance(html_outpath, str)
|
||||
outpath = os.path.join(html_outpath, wxid)
|
||||
if os.path.exists(outpath):
|
||||
shutil.rmtree(outpath, ignore_errors=True)
|
||||
# 复制pywxdump/ui/web/*到outpath
|
||||
web_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "ui", "web")
|
||||
shutil.copytree(web_path, outpath)
|
||||
|
||||
|
||||
code, ret = export_html(wxid, outpath, db_config, my_wxid=my_wxid)
|
||||
|
||||
if code:
|
||||
return ReJson(0, ret)
|
||||
else:
|
||||
return ReJson(2001, body=ret)
|
||||
|
||||
|
||||
# end 导出聊天记录 *******************************************************************************************************
|
||||
|
||||
# start 聊天记录分析api **************************************************************************************************
|
||||
|
@ -6,4 +6,5 @@
|
||||
# Date: 2024/04/20
|
||||
# -------------------------------------------------------------------------------
|
||||
from .exportCSV import export_csv
|
||||
from .exportJSON import export_json
|
||||
from .exportJSON import export_json
|
||||
from .exportHtml import export_html
|
||||
|
@ -8,8 +8,7 @@
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
|
||||
from pywxdump import DBHandler
|
||||
from ..__init__ import DBHandler
|
||||
|
||||
|
||||
def export_csv(wxid, outpath, db_config, my_wxid="我", page_size=5000):
|
||||
|
46
pywxdump/db/export/exportHtml.py
Normal file
46
pywxdump/db/export/exportHtml.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-#
|
||||
# -------------------------------------------------------------------------------
|
||||
# Name: exportCSV.py
|
||||
# Description:
|
||||
# Author: xaoyaoo
|
||||
# Date: 2024/04/20
|
||||
# -------------------------------------------------------------------------------
|
||||
import json
|
||||
import os
|
||||
from ..__init__ import DBHandler
|
||||
|
||||
|
||||
def export_html(wxid, outpath, db_config, my_wxid="我"):
|
||||
if not os.path.exists(outpath):
|
||||
outpath = os.path.join(os.getcwd(), "export" + os.sep + wxid)
|
||||
if not os.path.exists(outpath):
|
||||
os.makedirs(outpath)
|
||||
|
||||
db = DBHandler(db_config, my_wxid)
|
||||
|
||||
count = db.get_msgs_count(wxid)
|
||||
chatCount = count.get(wxid, 0)
|
||||
if chatCount == 0:
|
||||
return False, "没有聊天记录"
|
||||
|
||||
msgs, users = db.get_msgs(wxid, 0, chatCount + 1)
|
||||
if len(msgs) == 0:
|
||||
return False, "没有聊天记录"
|
||||
|
||||
data_js = (
|
||||
"localStorage.setItem('isUseLocalData', 't') // 't' : 'f' \n"
|
||||
f"const local_msg_count = {chatCount}\n"
|
||||
f"const local_mywxid = '{my_wxid}' \n"
|
||||
f"const local_user_list = {json.dumps(users, ensure_ascii=False, indent=None )} \n"
|
||||
f"const local_msg_list = {json.dumps(msgs, ensure_ascii=False, indent=None )} \n"
|
||||
)
|
||||
|
||||
save_path = os.path.join(outpath, f"data.js")
|
||||
with open(save_path, "w", encoding="utf-8") as f:
|
||||
f.write(data_js)
|
||||
|
||||
return True, f"导出成功: {outpath}"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
Loading…
Reference in New Issue
Block a user