Files
Birthday-Pool-Bot/birthday_pool_bot/notifications/cli.py

46 lines
1.1 KiB
Python

import asyncio
import typer
from birthday_pool_bot.repositories import RepositoriesContainer
from .service import NotificationsService
from .settings import NotificationsSettings
def callback(ctx: typer.Context):
ctx.obj["settings"] = ctx.obj["settings"].notifications
def run(ctx: typer.Context):
settings: NotificationsSettings = ctx.obj["settings"]
repositories_container: RepositoriesContainer = ctx.obj["repositories_container"]
service = NotificationsService(
settings=settings,
repositories_container=repositories_container,
)
asyncio.run(service.run())
def run_once(ctx: typer.Context):
settings: NotificationsSettings = ctx.obj["settings"]
repositories_container: RepositoriesContainer = ctx.obj["repositories_container"]
service = NotificationsService(
settings=settings,
repositories_container=repositories_container,
)
asyncio.run(service.send_notifications())
def get_cli() -> typer.Typer:
cli = typer.Typer()
cli.callback()(callback)
cli.command(name="run")(run)
cli.command(name="run-once")(run_once)
return cli