Modify README

This commit is contained in:
taizan-hokuto
2020-01-08 01:02:05 +09:00
parent 6befc2de95
commit 89d2f8978f

View File

@@ -46,11 +46,12 @@ def display(data):
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()
#entry point if __name__ == '__main__':
chat = LiveChat("rsHWP7IjMiw", callback = display) chat = LiveChat("rsHWP7IjMiw", callback = display)
while chat.is_alive(): while chat.is_alive():
time.sleep(3) #other background operation.
#other background operation. time.sleep(3)
``` ```
### asyncio context: ### asyncio context:
@@ -62,8 +63,8 @@ import asyncio
async def main(): async def main():
chat = LiveChatAsync("rsHWP7IjMiw", callback = func) chat = LiveChatAsync("rsHWP7IjMiw", callback = func)
while chat.is_alive(): while chat.is_alive():
await asyncio.sleep(3)
#other background operation. #other background operation.
await asyncio.sleep(3)
#callback function is automatically called. #callback function is automatically called.
async def func(data): async def func(data):
@@ -71,11 +72,12 @@ async def func(data):
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()
try: if __name__ == '__main__':
loop = asyncio.get_event_loop() try:
loop.run_until_complete(main()) loop = asyncio.get_event_loop()
except CancelledError: loop.run_until_complete(main())
pass except CancelledError:
pass
``` ```
@@ -97,9 +99,12 @@ while chat.is_alive():
time.sleep(polling/len(data['items'])) time.sleep(polling/len(data['items']))
``` ```
### replay: ### replay:
If specified video is not live,
automatically try to fetch archived chat data.
```python ```python
from pytchat import ReplayChat from pytchat import LiveChat
def main(): def main():
#seektime (seconds): start position of chat. #seektime (seconds): start position of chat.
@@ -110,7 +115,8 @@ def main():
print(f"{c.elapsedTime} [{c.author.name}]-{c.message} {c.amountString}") print(f"{c.elapsedTime} [{c.author.name}]-{c.message} {c.amountString}")
data.tick() data.tick()
main() if __name__ == '__main__':
main()
``` ```
## Structure of Default Processor ## Structure of Default Processor