导出聊天记录

This commit is contained in:
xaoyaoo 2024-01-14 20:21:06 +08:00
parent cd9db597bc
commit 9e3ddceab4
3 changed files with 66 additions and 1 deletions

View File

@ -8,3 +8,4 @@
from .db_parsing import read_img_dat, read_emoji, decompress_CompressContent, read_audio_buf, read_audio, \
parse_xml_string, read_BytesExtra
from .export_chat import export_csv, get_contact_list, get_chatroom_list, get_msg_list, get_chat_count
from .utils import get_type_name, get_name_typeid

View File

@ -73,7 +73,7 @@ def get_type_name(type_id: tuple):
(49, 1): "类似文字消息而不一样的消息",
(49, 5): "卡片式链接",
(49, 6): "文件",
(49, 8): "用户上传的 GIF 表情",
(49, 8): "用户上传的GIF表情",
(49, 19): "合并转发的聊天记录",
(49, 33): "分享的小程序",
(49, 36): "分享的小程序",
@ -96,6 +96,46 @@ def get_type_name(type_id: tuple):
return "未知"
def get_name_typeid(type_name: str):
"""
获取消息类型名称
:param type_id: 消息类型ID 元组 eg: (1, 0)
:return:
"""
type_name_dict = {
(1, 0): "文本",
(3, 0): "图片",
(34, 0): "语音",
(43, 0): "视频",
(47, 0): "动画表情",
(49, 0): "文件",
(49, 1): "类似文字消息而不一样的消息",
(49, 5): "卡片式链接",
(49, 6): "文件",
(49, 8): "用户上传的GIF表情",
(49, 19): "合并转发的聊天记录",
(49, 33): "分享的小程序",
(49, 36): "分享的小程序",
(49, 57): "带有引用的文本消息",
(49, 63): "视频号直播或直播回放等",
(49, 87): "群公告",
(49, 88): "视频号直播或直播回放等",
(49, 2000): "转账消息",
(49, 2003): "赠送红包封面",
(50, 0): "语音通话",
(10000, 0): "系统通知",
(10000, 4): "拍一拍",
(10000, 8000): "系统通知"
}
type_tup = []
for k, v in type_name_dict.items():
if v == type_name:
type_tup.append(k)
return type_tup
def get_md5(data):
"""
获取数据的 MD5

View File

@ -193,6 +193,30 @@ def get_audio(savePath):
return send_file(savePath)
# 导出聊天记录
@api.route('/api/export', methods=["GET", 'POST'])
def export():
"""
导出聊天记录
:return:
"""
export_type = request.json.get("export_type")
start_time = request.json.get("start_time")
end_time = request.json.get("end_time")
chat_type = request.json.get("chat_type")
username = request.json.get("username")
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 = []
for t in chat_type:
tup = analyzer.get_name_typeid(t)
if tup:
chat_type_tups += tup
if not chat_type_tups:
return ReJson(1002)
return ReJson(0, "")
# 这部分为专业工具的api
@api.route('/api/wxinfo', methods=["GET", 'POST'])
def get_wxinfo():