Example usage
To use chaturbate_poller
in a project:
"""Interactive usage of `chaturbate_poller` to fetch and print events."""
import asyncio
from asyncio import CancelledError
from contextlib import suppress
from rich.prompt import Confirm, Prompt
from chaturbate_poller import ChaturbateClient, format_message
async def main(username: str, token: str, *, testbed: bool) -> None:
"""Main event loop to fetch and process events from Chaturbate API."""
async with ChaturbateClient(username, token, testbed=testbed) as client:
next_url: str | None = None
while True:
response = await client.fetch_events(next_url)
for event in response.events:
if message := format_message(event):
print(message)
if not (next_url := response.next_url):
break
# Interactive user input
username = Prompt.ask("Enter your Chaturbate username")
token = Prompt.ask("Enter your Chaturbate API key", password=True)
testbed = Confirm.ask("Would you like to enable testbed mode?")
# Run the main function in an event loop
with suppress(CancelledError, KeyboardInterrupt):
try:
await main(username, token, testbed=testbed)
except RuntimeError:
task = asyncio.create_task(main(username, token, testbed=testbed))
await task
Enter your Chaturbate username:
Enter your Chaturbate API key:
Would you like to enable testbed mode? [y/n]:
mountaingod2_grey entered the room
mountaingod2_grey followed
mountaingod2_grey tipped 25 tokens with message: 'WOW!'