This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
JsonfileArchiver_
taizan-hokuto edited this page Feb 29, 2020
·
3 revisions
チャットのJSONデータを1行ごとにファイルに保存します。
保存するファイルパス(ファイル名含む)。
同名のファイルが存在する場合は、ファイル名末尾(拡張子の前)に連番を付与します。
バックグラウンドで取得したチャットデータをコンストラクタで指定したファイルに保存するとともに、次の形式の辞書を返します。
{
"save_path" : (ファイルの保存パス),
"total_lines" :(ファイルに書き込み済みデータの行数)
}
import asyncio
from pytchat import LiveChatAsync
video_id = "8PIe_F9MI80"
async def main():
chat = LiveChatAsync(
video_id,
callback = func,
processor = JsonfileArchiver("c:/temp/test.data")
)
while chat.is_alive():
await asyncio.sleep(5)
async def func(param):
pass
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(async_def_callback())
except asyncio.CancelledError:
print('Cancelled')
1行ずつJSONデータとして保存されます。
例:
{"addChatItemAction": {"item": {"liveChatTextMessageRenderer": {"message": {"runs": [{"text": ...}\n
{"addChatItemAction": {"item": {"liveChatPaidMessageRenderer": {"id": "xxx", "timestampUsec": ...}\n
{"addChatItemAction": {"item": {"liveChatTextMessageRenderer": {"message": {"runs": [{"text": ...}\n
ファイルを一括してJSONデータとして取り込むことはできません。
ファイルから1行ごとに読み込む必要があります。