## discord_data
Library to parse information from the discord data export, see more info [here](https://support.discord.com/hc/en-us/articles/360004027692).
The request to process the data has to be done manually, and it can take a while for them to deliver it to you.
### Install:
Requires `python3.7+`. To install with pip, run:
pip install discord_data
## Single Export
This takes the `messages` and `activity` directories as arguments, like:
```python
>>> from discord_data import parse_messages, parse_activity
>>> next(parse_messages("./discord/october_2020/messages"))
>>> next(parse_activity("./discord/october_2020/activity"))
```
`Message(mid='747951969171275807', dt=datetime.datetime(2020, 8, 25, 22, 54, 5, 726000, tzinfo=datetime.timezone.utc), channel=Channel(cid='464051583559139340', name='general', server_name='Dream World'), content='<:NotLikeThis:237729324885606403>', attachments='')`
`Activity(event_id='AQICfXBljgG+pYXCTRrwzy6MqgAAAAA=', event_type='start_listening', region_info=RegionInfo(city='cityNameHere', country_code='US', region_code='CA', time_zone='America/Los_Angeles'), fingerprint=Fingerprint(os='Mac OS X', os_version='16.1.0', browser='Discord Client', ip='216.58.195.78', isp=None, device=None, distro=None), timestamp=datetime.datetime(2016, 11, 26, 7, 8, 47))`
Each of these returns a `Generator`, so they only read from the (giant) JSON files as needed. If you want to process all the data, you can call `list` on it to consume the whole generator:
```python
from discord_data import parse_messages, parse_activity
msg = list(parse_messages("./discord/october_2020/messages"))
acts = list(parse_activity("./discord/october_2020/activity"))
```
The raw activity data includes lots of additional fields, this only includes items I thought would be useful. If you want to parse the JSON blobs yourself, you do so by using `from discord_data import parse_raw_activity`
## Merge Exports
Exports seem to be complete, but when a server is deleted, all messages in that server are deleted permanently, so I'd recommend periodically doing an export to make sure you don't lose anything.
I recommend you organize your exports like this:
```
discord
├── march_2021
│ ├── account
│ ├── activity
│ ├── messages
│ ├── programs
│ ├── README.txt
│ └── servers
└── october_2020
├── account
├── activity
├── messages
├── programs
├── README.txt
└── servers
```
The `discord` folder at the top would be the `export_dir` keyword argument to the `merge_activity` and `merge_messages` functions, which call the underlying parse functions:
You can choose to supply the arguments with `export_dir` or `paths`:
```python
# locates the corresponding `messages` directories in the folder structure
list(merge_messages(export_dir="./discord"))`
# supply a list of the message directories yourself
list(merge_messages(paths=["./discord/march_2021/messages", "./discord/october_2020/messages"]))
```
Created to be used as part of [`HPI`](https://github.com/seanbreckenridge/HPI)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共17个文件
py:6个
txt:3个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:discord_data-0.1.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
discord_data-0.1.0.tar.gz (17个子文件)
discord_data-0.1.0
MANIFEST.in 47B
PKG-INFO 4KB
discord_data
common.py 216B
py.typed 0B
__init__.py 177B
parse.py 4KB
model.py 2KB
merge.py 3KB
LICENSE 11KB
mypy.ini 380B
setup.cfg 38B
discord_data.egg-info
PKG-INFO 4KB
SOURCES.txt 327B
top_level.txt 13B
dependency_links.txt 1B
setup.py 1KB
README.md 3KB
共 17 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功