Example #1
0
def event_loop(is_daemon: bool):
    """
    启动事件循环拉取计划并弹出提醒。
    """
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config=config, )
    location_repository = repository_factory.for_location()
    params = Params(config=config)
    plan_repository = repository_factory.for_plan()
    task_repository = repository_factory.for_task()
    use_case = EventLoopUseCase(
        alerter=Alerter(),
        location_repository=location_repository,
        params=params,
        plan_repository=plan_repository,
        task_repository=task_repository,
    )
    try:
        if is_daemon:
            with daemon.DaemonContext():
                use_case.run()
        else:
            use_case.run()
    except InvalidLocationError as e:
        print('没有名为{}的地点'.format(e.name))
Example #2
0
def delete_plan(*, plan_id):
    """
    删除指定计划。
    """
    params = Params(plan_id=plan_id)
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config)
    use_case = DeletePlanUseCase(
        params=params,
        plan_repository=repository_factory.for_plan(),
    )
    use_case.run()
Example #3
0
def delete_task(*, task_id):
    """
    删除指定任务及其计划。
    """
    params = Params(task_id=task_id)
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config)
    use_case = DeleteTaskUseCase(
        params=params,
        presenter=ConsolePresenter(),
        task_repository=repository_factory.for_task(),
    )
    use_case.run()
Example #4
0
def list_plan(*, no_location: bool, page, per_page):
    """
    列出接下来的计划。
    """
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config=config, )
    use_case = ListPlanUseCase(
        location_repository=repository_factory.for_location(),
        params=Params(
            location_name=config['location']['name'],
            no_location=no_location,
            page=page,
            per_page=per_page,
        ),
        plan_repository=repository_factory.for_plan(),
        presenter=ConsolePresenter(),
        task_repository=repository_factory.for_task(),
    )
    use_case.run()
Example #5
0
def list_task(*, keyword, page, per_page, plan_trigger_time, status):
    """
    列出任务。
    """
    params = Params(
        keyword=keyword,
        page=page,
        per_page=per_page,
        plan_trigger_time=plan_trigger_time,
        status=status,
    )
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config)
    use_case = ListTaskUseCase(
        params=params,
        presenter=ConsolePresenter(),
        task_repository=repository_factory.for_task(),
    )
    use_case.run()
Example #6
0
def create_task(*, brief, keywords):
    """
    创建一个任务。
    """
    config = IniFileConfig()
    config.load()
    params = Params(
        brief=brief,
        keywords=keywords,
    )
    repository_factory = RepositoryFactory(config=config, )
    task_repository = repository_factory.for_task()
    use_case = CreateTaskUseCase(
        params=params,
        task_repository=task_repository,
    )
    task = use_case.run()
    click.echo(
        tabulate(
            headers=['任务ID', '任务简述'],
            tabular_data=[[task.id, task.brief]],
        ))
Example #7
0
def create_plan(duration, location_id: Optional[int], repeat_interval,
                repeat_type, task_id, trigger_time, visible_hours,
                visible_wdays):
    """
    为任务创建一个计划。
    """
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config=config, )
    use_case = CreatePlanUseCase(
        params=Params(
            duration=duration,
            location_id=location_id,
            repeat_interval=repeat_interval,
            repeat_type=repeat_type,
            task_id=task_id,
            trigger_time=trigger_time,
            visible_hours=visible_hours,
            visible_wdays=visible_wdays,
        ),
        plan_repository=repository_factory.for_plan(),
    )
    use_case.run()
Example #8
0
def change_plan(*, duration, location_id, plan_id, repeat_interval,
                repeat_type, trigger_time, visible_hours, visible_wdays):
    """
    修改指定计划。
    """
    params = Params(
        duration=duration,
        location_id=location_id,
        plan_id=plan_id,
        repeat_interval=repeat_interval,
        repeat_type=repeat_type,
        trigger_time=trigger_time,
        visible_hours=visible_hours,
        visible_wdays=visible_wdays,
    )
    config = IniFileConfig()
    config.load()
    repository_factory = RepositoryFactory(config)
    use_case = ChangePlanUseCase(
        params=params,
        plan_repository=repository_factory.for_plan(),
    )
    use_case.run()