JsonfileArchiver - taizan-hokuto/pytchat GitHub Wiki
JsonfileArchiver
- saves chat data as text of JSON lines.
Parameter
save_path : str
If a file with the same name exists, it is automatically saved under a different name with suffix '(number)'.
Return
dict : save_path : str -- actual save path of file. total_lines : int -- count of total lines written to the file.
Usage
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')
Data Format
This processor saves chat data as text of JSON lines. for example...
{"addChatItemAction": {"item": {"liveChatTextMessageRenderer": {"message": {"runs": [{"text": ...}\n
{"addChatItemAction": {"item": {"liveChatPaidMessageRenderer": {"id": "xxx", "timestampUsec": ...}\n
{"addChatItemAction": {"item": {"liveChatTextMessageRenderer": {"message": {"runs": [{"text": ...}\n
The entire file cannot be imported as one JSON file. You need to fetch and parse the JSON line by line.