# QQ 聊天记录提取器
## 简介
从 QQ 聊天记录文件中提取聊天信息,仅支持 `txt` 格式的聊天记录。
## 安装
使用 `pip` 安装,要求 `Python 3.9` 或以上版本。
```bash
> pip install -U qq-chat-history
```
## 使用
最简单的启动方式如下,它会自动在当前目录下创建 `output.json` 进行输出(如果安装到虚拟环境请确保已激活)。
```bash
> qq-chat-history /path/to/file.txt
```
启动时输入 `--help` 参数查看更多配置项。
```bash
> qq-chat-history --help
```
或者,可以作为一个第三方库使用,如下:
```python
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` 对象。
Raw data
{
"_id": null,
"home_page": "https://github.com/hikariyo/qq-chat-history",
"name": "qq-chat-history",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "hikariyo",
"author_email": "hikariyo1@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/7d/b5/77947f2187774b2693b46a3c8a51751176a3bcb399c00ff2f233256c477b/qq_chat_history-1.1.7.tar.gz",
"platform": null,
"description": "# QQ \u804a\u5929\u8bb0\u5f55\u63d0\u53d6\u5668\n\n## \u7b80\u4ecb\n\n\u4ece QQ \u804a\u5929\u8bb0\u5f55\u6587\u4ef6\u4e2d\u63d0\u53d6\u804a\u5929\u4fe1\u606f\uff0c\u4ec5\u652f\u6301 `txt` \u683c\u5f0f\u7684\u804a\u5929\u8bb0\u5f55\u3002\n\n\n## \u5b89\u88c5\n\n\u4f7f\u7528 `pip` \u5b89\u88c5\uff0c\u8981\u6c42 `Python 3.9` \u6216\u4ee5\u4e0a\u7248\u672c\u3002\n\n```bash\n> pip install -U qq-chat-history\n```\n\n## \u4f7f\u7528\n\n\u6700\u7b80\u5355\u7684\u542f\u52a8\u65b9\u5f0f\u5982\u4e0b\uff0c\u5b83\u4f1a\u81ea\u52a8\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa `output.json` \u8fdb\u884c\u8f93\u51fa\uff08\u5982\u679c\u5b89\u88c5\u5230\u865a\u62df\u73af\u5883\u8bf7\u786e\u4fdd\u5df2\u6fc0\u6d3b\uff09\u3002\n\n```bash\n> qq-chat-history /path/to/file.txt\n```\n\n\u542f\u52a8\u65f6\u8f93\u5165 `--help` \u53c2\u6570\u67e5\u770b\u66f4\u591a\u914d\u7f6e\u9879\u3002\n\n```bash\n> qq-chat-history --help\n```\n\n\u6216\u8005\uff0c\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5e93\u4f7f\u7528\uff0c\u5982\u4e0b\uff1a\n\n```python\nimport qq_chat_history\n\nlines = '''\n=========\n\u5047\u88c5\u6211\u662f QQ \u81ea\u52a8\u751f\u6210\u7684\u6587\u4ef6\u5934\n=========\n\n1883-03-07 11:22:33 A<someone@example.com>\nText A1\nText A2\n\n1883-03-07 12:34:56 B(123123)\nText B\n\n1883-03-07 13:24:36 C(456456)\nText C\n\n1883-03-07 22:00:51 A<someone@example.com>\nText D\n'''.strip().splitlines()\n\n# \u8fd9\u91cc\u7684 lines \u4e5f\u53ef\u4ee5\u662f\u6587\u4ef6\u5bf9\u8c61\u6216\u8005\u4ee5\u5b57\u7b26\u4e32\u6216\u8005 Path \u5bf9\u8c61\u8868\u793a\u7684\u6587\u4ef6\u8def\u5f84\u3002\nfor msg in qq_chat_history.parse(lines):\n print(msg.date, msg.id, msg.name, msg.content)\n```\n\n\u6ce8\u610f `parse` \u65b9\u6cd5\u8fd4\u56de\u7684\u662f\u4e00\u4e2a `Body` \u5bf9\u8c61\uff0c\u4e00\u822c\u4ee5 `Iterable[Message]` \u7684\u5f62\u5f0f\u4f7f\u7528\u3002\u5f53\u7136 `Body` \u4e5f\u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\uff0c~\u867d\u7136\u4e00\u822c\u4e5f\u6ca1\u4ec0\u4e48\u7528~\u3002\n\n## Tips\n\n+ \u5982\u679c\u5f53\u4f5c\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5e93\u6765\u7528\uff0c\u4f8b\u5982 `find_xxx` \u65b9\u6cd5\uff0c\u53ef\u4ee5\u4ece\u6570\u636e\u4e2d\u67e5\u627e\u6307\u5b9a `id` \u6216 `name` \u7684\u6d88\u606f\uff1b`save` \u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u636e\u4ee5 `yaml` \u6216 `json` \u683c\u5f0f\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u867d\u7136\u8fd9\u4e2a\u5de5\u4f5c\u4e00\u822c\u90fd\u76f4\u63a5\u4ee5 `CLI` \u6a21\u5f0f\u542f\u52a8\u6765\u5b8c\u6210\u3002\n\n+ \u51fd\u6570 `parse` \u53ef\u4ee5\u5904\u7406\u591a\u6837\u7684\u7c7b\u578b\u3002\n\n + `Iterable[str]`\uff1a\u8fed\u4ee3\u6bcf\u884c\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u5982 `list` \u6216 `tuple` \u7b49\u3002\n + `TextIOBase`\uff1a\u6587\u672c\u6587\u4ef6\u5bf9\u8c61\uff0c\u5982\u7528 `open` \u6253\u5f00\u7684\u6587\u672c\u6587\u4ef6\uff0c\u6216\u8005 `io.StringIO` \u90fd\u5c5e\u4e8e\u6587\u672c\u6587\u4ef6\u5bf9\u8c61\u3002\n + `str`, `Path`\uff1a\u6587\u4ef6\u8def\u5f84\uff0c\u5982 `./data.txt`\u3002\n\n \u8fd9\u4e9b\u53c2\u6570\u90fd\u5c06\u4ee5\u5bf9\u5e94\u7684\u65b9\u6cd5\u6765\u6784\u9020 `Body` \u5bf9\u8c61\u3002\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A tool to extract QQ chat history.",
"version": "1.1.7",
"project_urls": {
"Homepage": "https://github.com/hikariyo/qq-chat-history",
"Repository": "https://github.com/hikariyo/qq-chat-history"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f4756f2ea86ce2b06bb6c6fe83a372ac258c74c789355ea36c201071096de60",
"md5": "7cc8d30dbc6e75267a4ed0ad71cdd980",
"sha256": "8b11cf94d50033d7f53c6d3926d04127ec8d82efb4c3c9888ac9e9856bd6e134"
},
"downloads": -1,
"filename": "qq_chat_history-1.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7cc8d30dbc6e75267a4ed0ad71cdd980",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 6660,
"upload_time": "2023-10-14T17:45:28",
"upload_time_iso_8601": "2023-10-14T17:45:28.987078Z",
"url": "https://files.pythonhosted.org/packages/4f/47/56f2ea86ce2b06bb6c6fe83a372ac258c74c789355ea36c201071096de60/qq_chat_history-1.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7db577947f2187774b2693b46a3c8a51751176a3bcb399c00ff2f233256c477b",
"md5": "38f2c120904a2ea184d1765cf5f68f6e",
"sha256": "f466602d563e81c2bd8ced20891c160032ae82f33ec945cdc0c2601cde940a0a"
},
"downloads": -1,
"filename": "qq_chat_history-1.1.7.tar.gz",
"has_sig": false,
"md5_digest": "38f2c120904a2ea184d1765cf5f68f6e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 5971,
"upload_time": "2023-10-14T17:45:31",
"upload_time_iso_8601": "2023-10-14T17:45:31.231037Z",
"url": "https://files.pythonhosted.org/packages/7d/b5/77947f2187774b2693b46a3c8a51751176a3bcb399c00ff2f233256c477b/qq_chat_history-1.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-14 17:45:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hikariyo",
"github_project": "qq-chat-history",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "qq-chat-history"
}