Skip to content

Commit

Permalink
添加聊天记录选择展示
Browse files Browse the repository at this point in the history
  • Loading branch information
xaoyaoo committed Jan 16, 2024
1 parent 524c409 commit 9e2fa29
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
35 changes: 31 additions & 4 deletions pywxdump/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pywxdump import analyzer, read_img_dat, read_audio
from pywxdump.api.rjson import ReJson, RqJson
from pywxdump import read_info, VERSION_LIST, batch_decrypt, BiasAddr, merge_db
import pywxdump

# app = Flask(__name__, static_folder='../ui/web/dist', static_url_path='/')

Expand All @@ -28,19 +29,26 @@ def init():
# g.msg_path = path
# g.micro_path = path
# g.media_path = path
# g.wxid_path = r"C:\Users\xaoyo\Documents\Tencent\WeChat Files\wxid_vzzcn5fevion22"
# g.wx_path = r"C:\Users\xaoyo\Documents\Tencent\WeChat Files\wxid_vzzcn5fevion22"
# g.my_wxid = "wxid_vzzcn5fevion22"

rdata = {
"msg_path": "",
"micro_path": "",
"media_path": "",
"wxid_path": "",
"wx_path": "",
"my_wxid": "",
"is_init": False,
}
return ReJson(0, rdata)

@api.route('/api/version', methods=["GET", 'POST'])
def version():
"""
版本
:return:
"""
return ReJson(0, pywxdump.__version__)

@api.route('/api/contact_list', methods=["GET", 'POST'])
def contact_list():
Expand Down Expand Up @@ -171,7 +179,7 @@ def get_img():
img_path = request.json.get("img_path", img_path)
if not img_path:
return ReJson(1002)
img_path_all = os.path.join(g.wxid_path, img_path)
img_path_all = os.path.join(g.wx_path, img_path)
if os.path.exists(img_path_all):
fomt, md5, out_bytes = read_img_dat(img_path_all)
out_bytes = base64.b64encode(out_bytes).decode("utf-8")
Expand Down Expand Up @@ -213,6 +221,11 @@ def export():
end_time = request.json.get("end_time")
chat_type = request.json.get("chat_type")
username = request.json.get("username")

# 可选参数
wx_path = request.json.get("wx_path", g.wx_path)
key = request.json.get("key", "")

if not export_type or not start_time or not end_time or not chat_type or not username:
return ReJson(1002)
chat_type_tups = []
Expand All @@ -228,14 +241,28 @@ def export():
if not os.path.exists(outpath):
os.makedirs(outpath)

if export_type == "csv":
if export_type == "endb":
pass
elif export_type == "dedb":
pass
elif 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)
elif export_type == "json":
pass
elif export_type == "html":
pass
elif export_type == "pdf":
pass
elif export_type == "docx":
pass
else:
return ReJson(1002)

return ReJson(0, "")

Expand Down
16 changes: 11 additions & 5 deletions pywxdump/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def init_parses(self, parser):
sb_decrypt.add_argument("-media", "--media_path", type=str, help="解密后的 MediaMSG.db 的路径", required=False,
metavar="")

sb_decrypt.add_argument("-wid", "--wxid_path", type=str,
sb_decrypt.add_argument("-wid", "--wx_path", type=str,
help="(可选)微信文件夹的路径(用于显示图片)", required=False,
metavar="")
sb_decrypt.add_argument("-myid", "--my_wxid", type=str, help="(可选)微信账号(本人微信id)", required=False,
Expand Down Expand Up @@ -237,7 +237,8 @@ def before_request():
g.msg_path = args.msg_path
g.micro_path = args.micro_path
g.media_path = args.media_path
g.wxid_path = args.wxid_path
g.wx_path = args.wx_path
# g.key = args.key
g.my_wxid = args.my_wxid
g.tmp_path = os.path.join(os.getcwd(), "wxdump_tmp") # 临时文件夹,用于存放图片等
g.user_list = []
Expand Down Expand Up @@ -448,7 +449,7 @@ def run(self, args):
args.msg_path = merge_save_path
args.micro_path = merge_save_path
args.media_path = merge_save_path
args.wxid_path = filePath
args.wx_path = filePath
args.my_wxid = wxid
args.online = online
MainShowChatRecords().run(args)
Expand Down Expand Up @@ -492,7 +493,7 @@ def run(self, args):
def before_request():
g.msg_path = ""
g.media_path = ""
g.wxid_path = ""
g.wx_path = ""
g.my_wxid = ""
g.tmp_path = os.path.join(os.getcwd(), "wxdump_tmp") # 临时文件夹,用于存放图片等
g.user_list = []
Expand Down Expand Up @@ -601,11 +602,16 @@ def console_run():
sb_all = main_all.init_parses(subparsers)
modes[main_all.mode] = main_all

# 添加 'ui' 子命令解析器
main_ui = MainUi()
sb_ui = main_ui.init_parses(subparsers)
modes[main_ui.mode] = main_ui

# 检查是否需要显示帮助信息
if len(sys.argv) == 1:
sys.argv.append('all')
elif len(sys.argv) == 2 and sys.argv[1] in modes.keys() and sys.argv[1] not in [main_all.mode, main_wx_info.mode,
main_wx_db_path.mode]:
main_wx_db_path.mode, main_ui.mode]:
sys.argv.append('-h')

args = parser.parse_args() # 解析命令行参数
Expand Down
2 changes: 1 addition & 1 deletion pywxdump/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def before_request():
g.msg_path = path
g.micro_path = path
g.media_path = path
g.wxid_path = r"*****"
g.wx_path = r"*****"
g.my_wxid = "******"
g.tmp_path = "dist" # 临时文件夹,用于存放图片等
g.user_list = []
Expand Down

0 comments on commit 9e2fa29

Please sign in to comment.