Fix README

This commit is contained in:
taizan-hokuto
2019-12-21 22:40:08 +09:00
parent ab5a2a8df2
commit dc47f4debe

View File

@@ -8,7 +8,7 @@ pytchat is a python library for fetching youtube live chat
without using youtube api, Selenium or BeautifulSoup. without using youtube api, Selenium or BeautifulSoup.
Other features: Other features:
+ Customizable chat data processors including yt api compatible one. + Customizable chat data processors including youtube api compatible one.
+ Available on asyncio context. + Available on asyncio context.
+ Quick fetching of initial chat data by generating continuation params + Quick fetching of initial chat data by generating continuation params
instead of web scraping. instead of web scraping.
@@ -29,10 +29,10 @@ from pytchat import LiveChat
chat = LiveChat("G1w62uEMZ74") chat = LiveChat("G1w62uEMZ74")
while chat.is_alive(): while chat.is_alive():
data = chat.get() data = chat.get()
for c in data.items: for c in data.items:
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}") print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
data.tick() data.tick()
``` ```
### callback mode ### callback mode
@@ -41,16 +41,16 @@ from pytchat import LiveChat
import time import time
def main() def main()
chat = LiveChat("G1w62uEMZ74", callback = func) chat = LiveChat("G1w62uEMZ74", callback = func)
while chat.is_alive(): while chat.is_alive():
time.sleep(3) time.sleep(3)
#other background operation. #other background operation.
#callback function is automatically called periodically. #callback function is automatically called periodically.
def func(data): def func(data):
for c in data.items: for c in data.items:
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}") print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
data.tick() data.tick()
``` ```
### asyncio context: ### asyncio context:
@@ -59,16 +59,16 @@ from pytchat import LiveChatAsync
import asyncio import asyncio
async def main(): async def main():
chat = LiveChatAsync("G1w62uEMZ74", callback = func) chat = LiveChatAsync("G1w62uEMZ74", callback = func)
while chat.is_alive(): while chat.is_alive():
await asyncio.sleep(3) await asyncio.sleep(3)
#other background operation. #other background operation.
#callback function is automatically called periodically. #callback function is automatically called periodically.
async def func(data): async def func(data):
for c in data.items: for c in data.items:
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}") print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
await data.tick_async() await data.tick_async()
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(main()) loop.run_until_complete(main())
@@ -80,16 +80,16 @@ loop.run_until_complete(main())
from pytchat import LiveChat, CompatibleProcessor from pytchat import LiveChat, CompatibleProcessor
chat = LiveChat("G1w62uEMZ74", chat = LiveChat("G1w62uEMZ74",
processor = CompatibleProcessor() ) processor = CompatibleProcessor() )
while chat.is_alive(): while chat.is_alive():
data = chat.get() data = chat.get()
polling = data["pollingIntervalMillis"]/1000 polling = data["pollingIntervalMillis"]/1000
for c in data["items"]: for c in data["items"]:
if c.get("snippet"): if c.get("snippet"):
print(f"[{c['authorDetails']['displayName']}]" print(f"[{c['authorDetails']['displayName']}]"
f"-{c['snippet']['displayMessage']}") f"-{c['snippet']['displayMessage']}")
time.sleep(polling/len(data["items"])) time.sleep(polling/len(data["items"]))
``` ```
### replay: ### replay:
@@ -98,21 +98,21 @@ from pytchat import ReplayChatAsync
import asyncio import asyncio
async def main(): async def main():
chat = ReplayChatAsync("G1w62uEMZ74", seektime = 1000, callback = func) chat = ReplayChatAsync("G1w62uEMZ74", seektime = 1000, callback = func)
while chat.is_alive(): while chat.is_alive():
await asyncio.sleep(3) await asyncio.sleep(3)
#other background operation here. #other background operation here.
#callback function is automatically called periodically. #callback function is automatically called periodically.
async def func(data): async def func(data):
for count in range(0,len(data.items)): for count in range(0,len(data.items)):
c= data.items[count] c= data.items[count]
if count!=len(data.items): if count!=len(data.items):
tick=data.items[count+1].timestamp -data.items[count].timestamp tick=data.items[count+1].timestamp -data.items[count].timestamp
else: else:
tick=0 tick=0
print(f"<{c.elapsedTime}> [{c.author.name}]-{c.message} {c.amountString}") print(f"<{c.elapsedTime}> [{c.author.name}]-{c.message} {c.amountString}")
await asyncio.sleep(tick/1000) await asyncio.sleep(tick/1000)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(main()) loop.run_until_complete(main())