Skip to main content

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>
Text A1
Text A2

1883-03-07 12:34:56 B(123123)
Text B

1883-03-07 13:24:36 C(456456)
Text C

1883-03-07 22:00:51 A<someone@example.com>
Text D
'''.strip().splitlines()

# 这里的 lines 也可以是文件对象或者以字符串或者 Path 对象表示的文件路径。
for msg in qq_chat_history.parse(lines):
    print(msg.date, msg.id, msg.name, msg.content)

注意 parse 方法返回的是一个 Body 对象,一般以 Iterable[Message] 的形式使用。当然 Body 也提供了几个函数,虽然一般也没什么用。

Tips

  • 如果当作一个第三方库来用,例如 find_xxx 方法,可以从数据中查找指定 id 或 name 的消息;save 方法可以将数据以 yaml 或 json 格式保存到文件中,虽然这个工作一般都直接以 CLI 模式启动来完成。

  • 函数 parse 可以处理多样的类型。

    • Iterable[str]:迭代每行的可迭代对象,如 list 或 tuple 等。
    • TextIOBase:文本文件对象,如用 open 打开的文本文件,或者 io.StringIO 都属于文本文件对象。
    • str, Path:文件路径,如 ./data.txt。

    这些参数都将以对应的方法来构造 Body 对象。

Metadata

Release files for qq-chat-history 1.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qq-chat-history 1.1.7
File Size Uploaded
qq_chat_history-1.1.7.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qq-chat-history 1.1.7
File Interpreter ABI Platform
qq_chat_history-1.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / qq_chat_history-1.1.7.tar.gz

Download URL qq_chat_history-1.1.7.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f466602d563e81c2bd8ced20891c160032ae82f33ec945cdc0c2601cde940a0a
BLAKE2b-256 checksum
How to use checksums
7db577947f2187774b2693b46a3c8a51751176a3bcb399c00ff2f233256c477b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Windows/10

Release files / qq_chat_history-1.1.7-py3-none-any.whl

Download URL qq_chat_history-1.1.7-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b11cf94d50033d7f53c6d3926d04127ec8d82efb4c3c9888ac9e9856bd6e134
BLAKE2b-256 checksum
How to use checksums
4f4756f2ea86ce2b06bb6c6fe83a372ac258c74c789355ea36c201071096de60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Windows/10

Release history Release notifications | RSS feed

This release

1.1.7 This release

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page