2021-08-04 18:53:58 +02:00
|
|
|
import functools
|
|
|
|
|
|
|
|
import click
|
|
|
|
from arrow import Arrow
|
|
|
|
from click import pass_context, pass_obj
|
|
|
|
|
|
|
|
from mobilizon_bots.cli import safe_execution
|
2021-08-05 00:29:50 +02:00
|
|
|
from mobilizon_bots.cli.inspect_event import inspect_events
|
2021-08-04 18:53:58 +02:00
|
|
|
from mobilizon_bots.cli.main import main
|
|
|
|
from mobilizon_bots.event.event import EventPublicationStatus
|
|
|
|
|
|
|
|
settings_file_option = click.option("--settings-file", type=click.Path(exists=True))
|
2021-08-14 18:23:55 +02:00
|
|
|
from_date_option = click.option(
|
|
|
|
"--begin",
|
|
|
|
type=click.DateTime(),
|
|
|
|
expose_value=True,
|
|
|
|
help="Include only events that begin after this datetime",
|
|
|
|
)
|
|
|
|
to_date_option = click.option(
|
|
|
|
"--end",
|
|
|
|
type=click.DateTime(),
|
|
|
|
expose_value=True,
|
|
|
|
help="Include only events that begin before this datetime",
|
|
|
|
)
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def mobilizon_bots():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@mobilizon_bots.command()
|
|
|
|
@settings_file_option
|
|
|
|
def start(settings_file):
|
|
|
|
safe_execution(main, settings_file=settings_file)
|
|
|
|
|
|
|
|
|
|
|
|
@mobilizon_bots.group()
|
|
|
|
@from_date_option
|
|
|
|
@to_date_option
|
|
|
|
@pass_context
|
|
|
|
def inspect(ctx, begin, end):
|
|
|
|
ctx.ensure_object(dict)
|
|
|
|
ctx.obj["begin"] = Arrow.fromdatetime(begin) if begin else None
|
|
|
|
ctx.obj["end"] = Arrow.fromdatetime(end) if end else None
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@inspect.command()
|
|
|
|
@settings_file_option
|
2021-08-14 18:23:55 +02:00
|
|
|
@pass_obj
|
|
|
|
def all(obj, settings_file):
|
|
|
|
safe_execution(
|
|
|
|
functools.partial(inspect_events, frm=obj["begin"], to=obj["end"],),
|
|
|
|
settings_file,
|
|
|
|
)
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
@inspect.command()
|
|
|
|
@pass_obj
|
2021-08-14 18:23:55 +02:00
|
|
|
@settings_file_option
|
2021-08-04 18:53:58 +02:00
|
|
|
def waiting(obj, settings_file):
|
|
|
|
safe_execution(
|
|
|
|
functools.partial(
|
|
|
|
inspect_events,
|
|
|
|
EventPublicationStatus.WAITING,
|
|
|
|
frm=obj["begin"],
|
|
|
|
to=obj["end"],
|
|
|
|
),
|
|
|
|
settings_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@inspect.command()
|
|
|
|
@pass_obj
|
2021-08-14 18:23:55 +02:00
|
|
|
@settings_file_option
|
2021-08-04 18:53:58 +02:00
|
|
|
def failed(obj, settings_file):
|
|
|
|
safe_execution(
|
|
|
|
functools.partial(
|
|
|
|
inspect_events,
|
|
|
|
EventPublicationStatus.FAILED,
|
|
|
|
frm=obj["begin"],
|
|
|
|
to=obj["end"],
|
|
|
|
),
|
|
|
|
settings_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@inspect.command()
|
|
|
|
@pass_obj
|
2021-08-14 18:23:55 +02:00
|
|
|
@settings_file_option
|
2021-08-04 18:53:58 +02:00
|
|
|
def partial(obj, settings_file):
|
|
|
|
safe_execution(
|
|
|
|
functools.partial(
|
|
|
|
inspect_events,
|
|
|
|
EventPublicationStatus.PARTIAL,
|
|
|
|
frm=obj["begin"],
|
|
|
|
to=obj["end"],
|
|
|
|
),
|
|
|
|
settings_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@inspect.command()
|
|
|
|
@settings_file_option
|
|
|
|
@pass_obj
|
|
|
|
def completed(obj, settings_file):
|
|
|
|
safe_execution(
|
|
|
|
functools.partial(
|
|
|
|
inspect_events,
|
|
|
|
EventPublicationStatus.COMPLETED,
|
|
|
|
frm=obj["begin"],
|
|
|
|
to=obj["end"],
|
|
|
|
),
|
|
|
|
settings_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
mobilizon_bots()
|