添加使用说明

This commit is contained in:
SiYuan 2025-03-28 23:43:00 +08:00
parent 6535ed011c
commit 8ef61ab61a
6 changed files with 263 additions and 165 deletions

View File

@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
"""
@Time : 2025/3/11 18:17
@Time : 2025/3/11 20:27
@Author : SiYuan
@Email : 863909694@qq.com
@File : WeChatMsg-1-decrypt.py
@File : wxManager-1-decrypt.py
@Description :
"""
@ -16,13 +16,12 @@ from multiprocessing import freeze_support
from wxManager import Me
from wxManager.decrypt import get_info_v4, get_info_v3
from wxManager.decrypt.decrypt_dat import get_decode_code_v4
from wxManager.decrypt.decrypt_v4 import decrypt_db_files
from wxManager.decrypt import decrypt_v4, decrypt_v3
if __name__ == '__main__':
freeze_support() # 使用多进程必须
# r_4 = get_info_v4() # 微信4.0
r_4 = []
r_4 = get_info_v4() # 微信4.0
for wx_info in r_4:
print(wx_info)
me = Me()
@ -34,7 +33,7 @@ if __name__ == '__main__':
output_dir = wx_info.wxid
key = wx_info.key
wx_dir = wx_info.wx_dir
decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
decrypt_v4.decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'db_storage', 'info.json'), 'w', encoding='utf-8') as f:
json.dump(info_data, f, ensure_ascii=False, indent=4)
@ -52,6 +51,6 @@ if __name__ == '__main__':
output_dir = wx_info.wxid
key = wx_info.key
wx_dir = wx_info.wx_dir
# decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'info.json'), 'w', encoding='utf-8') as f:
decrypt_v3.decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'Msg', 'info.json'), 'w', encoding='utf-8') as f:
json.dump(info_data, f, ensure_ascii=False, indent=4)

40
example/2-contact.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2025/3/11 20:46
@Author : SiYuan
@Email : 863909694@qq.com
@File : wxManager-2-contact.py
@Description :
"""
import time
from wxManager import DatabaseConnection
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
st = time.time()
cnt = 0
contacts = database.get_contacts()
for contact in contacts:
print(contact)
contact.small_head_img_blog = database.get_avatar_buffer(contact.wxid)
cnt += 1
if contact.is_chatroom:
print('*' * 80)
print(contact)
chatroom_members = database.get_chatroom_members(contact.wxid)
print(contact.wxid, '群成员个数:', len(chatroom_members))
for wxid, chatroom_member in chatroom_members.items():
chatroom_member.small_head_img_blog = database.get_avatar_buffer(wxid)
print(chatroom_member)
cnt += 1
et = time.time()
print(f'联系人个数:{cnt} 耗时:{et - st:.2f}s')

124
example/3-exporter.py Normal file
View File

@ -0,0 +1,124 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2025/3/11 20:50
@Author : SiYuan
@Email : 863909694@qq.com
@File : wxManager-3-exporter.py
@Description :
"""
import time
from multiprocessing import freeze_support
from exporter.config import FileType
from exporter import HtmlExporter, TxtExporter, AiTxtExporter, DocxExporter, MarkdownExporter, ExcelExporter
from wxManager import DatabaseConnection, MessageType
def export():
st = time.time()
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
wxid = 'wxid_00112233' # 要导出好友的wxid
output_dir = './data/' # 输出文件夹
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
contact = database.get_contact_by_username(wxid) # 查找某个联系人
exporter = HtmlExporter(
database,
contact,
output_dir=output_dir,
type_=FileType.HTML,
message_types={MessageType.MergedMessages}, # 要导出的消息类型,默认全导出
time_range=['2020-01-01 00:00:00', '2035-03-12 00:00:00'], # 要导出的日期范围,默认全导出
group_members=None # 指定导出群聊里某个或者几个群成员的聊天记录
)
exporter.start()
et = time.time()
print(f'耗时:{et - st:.2f}s')
def batch_export():
"""
批量导出HTML
:return:
"""
st = time.time()
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
output_dir = './data/' # 输出文件夹
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
contacts = database.get_contacts() # 查找某个联系人
for contact in contacts:
exporter = HtmlExporter(
database,
contact,
output_dir=output_dir,
type_=FileType.HTML,
message_types={MessageType.Text, MessageType.Image, MessageType.LinkMessage}, # 要导出的消息类型,默认全导出
time_range=['2020-01-01 00:00:00', '2035-03-12 00:00:00'], # 要导出的日期范围,默认全导出
group_members=None # 指定导出群聊里某个或者几个群成员的聊天记录
)
exporter.start()
et = time.time()
print(f'耗时:{et - st:.2f}s')
def batch_export_by_fmt():
"""
批量导出多种格式
:return:
"""
st = time.time()
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
wxid = 'wxid_00112233' # 要导出好友的wxid
output_dir = './data/' # 输出文件夹
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
contact = database.get_contact_by_username(wxid) # 查找某个联系人
exporters = {
FileType.HTML: HtmlExporter,
FileType.TXT: TxtExporter,
FileType.AI_TXT: AiTxtExporter,
FileType.MARKDOWN: MarkdownExporter,
FileType.XLSX: ExcelExporter,
FileType.DOCX: DocxExporter
}
for file_type, exporter in exporters.items():
execute = exporter(
database,
contact,
output_dir=output_dir,
type_=file_type,
message_types=None, # 要导出的消息类型,默认全导出
time_range=['2020-01-01 00:00:00', '2035-03-12 00:00:00'], # 要导出的日期范围,默认全导出
group_members=None # 指定导出群聊里某个或者几个群成员的聊天记录
)
execute.start()
et = time.time()
print(f'耗时:{et - st:.2f}s')
if __name__ == '__main__':
freeze_support()
export()
# batch_export()
# batch_export_by_fmt()

View File

@ -1,197 +1,131 @@
## wxManager使用教程
### 1、解析数据
## 1、解析数据
```python
import json
import os
import time
from multiprocessing import freeze_support
import pymem
from wxManager import Me
from wxManager.decrypt import get_wx_info
from wxManager.decrypt import get_info_v4, get_info_v3
from wxManager.decrypt.decrypt_dat import get_decode_code_v4
from wxManager.decrypt.wxinfo import dump_wechat_info_v4_
from wxManager.decrypt.decrypt import decrypt_db_files
def dump_v4():
freeze_support()
st = time.time()
pm = pymem.Pymem("Weixin.exe")
pid = pm.process_id
w = dump_wechat_info_v4_(pid)
if w:
print(w)
et = time.time()
print(et - st)
me = Me()
me.wx_dir = w.wx_dir
me.wxid = w.wxid
me.name = w.nick_name
me.xor_key = get_decode_code_v4(w.wx_dir)
info_data = me.to_json()
output_dir = w.wxid
key = w.key
wx_dir = w.wx_dir
decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'db_storage', 'info.json'), 'w', encoding='utf-8') as f:
json.dump(info_data, f, ensure_ascii=False, indent=4)
else:
print('数据解析失败')
def dump_v3():
version__list_path = '../../wxManager/decrypt/version_list.json'
with open(version__list_path, "r", encoding="utf-8") as f:
version__list = json.loads(f.read())
wx_info_v3 = get_wx_info.get_info_v3(version__list)
for wx_info in wx_info_v3:
errcode = wx_info.get('errcode')
if errcode == 405:
print(wx_info.get('errmsg'))
elif errcode == 200:
print(wx_info)
from wxManager.decrypt import decrypt_v4, decrypt_v3
if __name__ == '__main__':
dump_v4()
# dump_v3()
freeze_support() # 使用多进程必须
r_4 = get_info_v4() # 微信4.0
for wx_info in r_4:
print(wx_info)
me = Me()
me.wx_dir = wx_info.wx_dir
me.wxid = wx_info.wxid
me.name = wx_info.nick_name
me.xor_key = get_decode_code_v4(wx_info.wx_dir)
info_data = me.to_json()
output_dir = wx_info.wxid
key = wx_info.key
wx_dir = wx_info.wx_dir
decrypt_v4.decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'db_storage', 'info.json'), 'w', encoding='utf-8') as f:
json.dump(info_data, f, ensure_ascii=False, indent=4)
version_list_path = '../wxManager/decrypt/version_list.json'
with open(version_list_path, "r", encoding="utf-8") as f:
version_list = json.loads(f.read())
r_3 = get_info_v3(version_list) # 微信3.x
for wx_info in r_3:
print(wx_info)
me = Me()
me.wx_dir = wx_info.wx_dir
me.wxid = wx_info.wxid
me.name = wx_info.nick_name
info_data = me.to_json()
output_dir = wx_info.wxid
key = wx_info.key
wx_dir = wx_info.wx_dir
decrypt_v3.decrypt_db_files(key, src_dir=wx_dir, dest_dir=output_dir)
with open(os.path.join(output_dir, 'Msg', 'info.json'), 'w', encoding='utf-8') as f:
json.dump(info_data, f, ensure_ascii=False, indent=4)
```
### 2、导出聊天记录
#### 查看联系人
## 2、查看联系人
```python
import time
from wxManager import DatabaseConnection
db_dir = '' # 数据库路径
conn = DatabaseConnection(db_dir, db_version=4)
database = conn.get_interface()
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
st = time.time()
cnt = 0
contacts = database.get_contacts()
for contact in contacts:
contact.smallHeadImgBLOG = database.get_avatar_buffer(contact.wxid) # 头像
print(contact)
contact.small_head_img_blog = database.get_avatar_buffer(contact.wxid)
cnt += 1
if contact.is_chatroom:
print('*' * 80)
print(contact)
chatroom_members = database.get_chatroom_members(contact.wxid)
print('群成员个数:', len(chatroom_members))
print(contact.wxid, '群成员个数:', len(chatroom_members))
for wxid, chatroom_member in chatroom_members.items():
chatroom_member.smallHeadImgBLOG = database.get_avatar_buffer(wxid)
chatroom_member.small_head_img_blog = database.get_avatar_buffer(wxid)
print(chatroom_member)
cnt += 1
et = time.time()
print(f'联系人个数:{cnt} 耗时:{et - st:.2f}s')
```
#### 导出TXT
```python
from exporter.config import FileType
from exporter.exporter_txt import TxtExporter
from wxManager import DatabaseConnection
db_dir = '' # 数据库路径
wxid = '' # 要导出联系人的wxid
output_dir = './data/' # 输出文件夹
conn = DatabaseConnection(db_dir, db_version=4)
database = conn.get_interface()
contact = database.get_contact_by_username(wxid)
exporter = TxtExporter(
database,
contact,
output_dir=output_dir,
type_=FileType.TXT,
message_types=None,
time_range=None,
group_members=None
)
# 设置自定义进度回调函数
def update_progress(progress):
print(progress)
exporter.set_update_callback(update_progress)
exporter.start()
```
#### 导出Excel
```python
from multiprocessing import freeze_support
from exporter.config import FileType
from exporter.exporter_xlsx import ExcelExporter
from wxManager import DatabaseConnection
if __name__ == '__main__':
freeze_support()
db_dir = '' # 解析后的数据库文件夹
wxid = 'xxx'
output_dir = './data/'
conn = DatabaseConnection(db_dir, db_version=4)
database = conn.get_interface()
contact = database.get_contact_by_username(wxid)
exporter = ExcelExporter(
database,
contact,
output_dir=output_dir,
type_=FileType.XLSX,
message_types=None,
time_range=None,
group_members=None
)
def update_progress(progress):
print(progress)
# exporter.set_update_callback(update_progress)
exporter.start()
```
#### 导出HTML
## 3、导出数据
```python
import time
from multiprocessing import freeze_support
from exporter.config import FileType
from exporter.exporter_html import HtmlExporterBase
from wxManager import DatabaseConnection
from exporter import HtmlExporter, TxtExporter, AiTxtExporter, DocxExporter, MarkdownExporter, ExcelExporter
from wxManager import DatabaseConnection, MessageType
if __name__ == '__main__':
freeze_support()
def export():
st = time.time()
db_dir = '' # 解析后的数据库文件夹
wxid = '' # 要导出好友的wxid
db_dir = '' # 解析后的数据库路径,例如:./db_storage
db_version = 4 # 数据库版本4 or 3
wxid = 'wxid_00112233' # 要导出好友的wxid
output_dir = './data/' # 输出文件夹
conn = DatabaseConnection(db_dir, db_version=4)
database = conn.get_interface()
contact = database.get_contact_by_username(wxid)
conn = DatabaseConnection(db_dir, db_version) # 创建数据库连接
database = conn.get_interface() # 获取数据库接口
exporter = HtmlExporterBase(
contact = database.get_contact_by_username(wxid) # 查找某个联系人
exporter = HtmlExporter(
database,
contact,
output_dir=output_dir,
type_=FileType.TXT,
message_types=None,
time_range=None,
group_members=None
type_=FileType.HTML,
message_types={MessageType.MergedMessages}, # 要导出的消息类型,默认全导出
time_range=['2020-01-01 00:00:00', '2035-03-12 00:00:00'], # 要导出的日期范围,默认全导出
group_members=None # 指定导出群聊里某个或者几个群成员的聊天记录
)
def update_progress(progress):
print(progress)
exporter.set_update_callback(update_progress)
exporter.start()
et = time.time()
print(f'耗时:{et - st:.2f}s')
if __name__ == '__main__':
freeze_support()
export()
```

View File

@ -1,7 +1,7 @@
# from exporter.exporter_txt import TxtExporter
# from exporter.exporter_ai_txt import AiTxtExporter
# from exporter.exporter_csv import CSVExporter
# from exporter.exporter_html import HtmlExporter
# from exporter.exporter_docx import DocxExporter
# from exporter.exporter_markdown import MarkdownExporter
# from exporter.exporter_xlsx import ExcelExporter
from exporter.exporter_txt import TxtExporter
from exporter.exporter_ai_txt import AiTxtExporter
from exporter.exporter_csv import CSVExporter
from exporter.exporter_html import HtmlExporter
from exporter.exporter_docx import DocxExporter
from exporter.exporter_markdown import MarkdownExporter
from exporter.exporter_xlsx import ExcelExporter

View File

@ -120,6 +120,7 @@
## 源码运行
[使用示例](./example/README.md)
[详见开发者手册](./doc/开发者手册.md)
[AI聊天](./MemoAI/readme.md)