Init project
This commit is contained in:
44
birthday_pool_bot/notifications/cli.py
Normal file
44
birthday_pool_bot/notifications/cli.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import asyncio
|
||||
|
||||
import typer
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user