A tool to extract QQ chat history.
Project description
QQ 聊天记录提取器
简介
从 QQ 聊天记录文件中提取聊天信息,仅支持 txt
格式的聊天记录。
安装
使用 pip
安装,要求 Python 3.9
或以上版本。
> pip install -U qq-chat-history
使用
最简单的启动方式如下,它会自动在当前目录下创建 output.json
进行输出(如果安装到虚拟环境请确保已激活)。
> qq-chat-history /path/to/file.txt
启动时输入 --help
参数查看更多配置项。
> qq-chat-history --help
或者,可以在代码中使用,如下:
import qq_chat_history
lines = '''
=========
假装我是 QQ 自动生成的文件头
=========
1883-03-07 11:22:33 A<someone@example.com>
关注永雏塔菲喵
关注永雏塔菲谢谢喵
1883-03-07 12:34:56 B(123123)
TCG
1883-03-07 13:24:36 C(456456)
TCG
1883-03-07 22:00:51 A<someone@example.com>
塔菲怎么你了
'''.strip().splitlines()
for msg in qq_chat_history.parse(lines):
print(msg.date, msg.id, msg.name, msg.content)
注意 parse
方法返回的是一个 Body
对象,一般以 Iterable[Message]
的形式使用。除外,Body
也提供了几个函数,虽然一般也没什么用。
Tips
-
在
0.3.0+
版本中,对于parse
方法的实现进行了大调整,它将返回一个Body
类,原先是Iterable[Message]
。但这并不会导致兼容性问题,因为Body
也是一个Iterable[Message]
。不同的是,
Body
类相对于原先单纯的生成器提供更多功能,例如find_xxx
方法,可以从数据中查找指定id
或name
的消息;save
方法可以将数据以yaml
或json
格式保存到文件中,虽然这个工作一般都直接以CLI
模式启动来完成。 -
在
0.3.0+
版本中,你可以向parse
中传入多种多样的类型。Iterable[str]
:迭代每行的可迭代对象,如list
或tuple
等。TextIOBase
:文本文件对象,如用open
打开的文本文件,或者io.StringIO
都属于文本文件对象。str
,Path
:文件路径,如./data.txt
。
这些参数都将被调用合适的工厂方法来构造
Body
对象。 -
由于
parse
这个名字的含义比较不清晰,推荐与不推荐的使用方式如下:# Not recommended 👎 from qq_chat_history import parse parse(...) # Recommended 👍 import qq_chat_history qq_chat_history.parse(...) from qq_chat_history import parse as parse_qq parse_qq(...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qq_chat_history-1.1.2.tar.gz
(6.4 kB
view hashes)
Built Distribution
Close
Hashes for qq_chat_history-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a775f2a397d8e8315ef4ce04de053604c7fd07ee218c098ee56bc11e6e21b3fe |
|
MD5 | fb8694da705dd845edfa7c5685c13335 |
|
BLAKE2b-256 | 043033c1ebaf63bb46079dd25bf891af258008c09ff24927847fcc253362b70b |