Exemple #1
0
def sources():
    while True:
        option = prompts.prompt_options(get_msg("Choose a Source Option"), [
            "new", "edit", "delete", None, "list", "test", None, "back to menu"
        ],
                                        print_options=False,
                                        menu_style=True,
                                        menu_title=get_title("Sources"))

        if option == "back to menu":
            return

        elif option == "new":
            source.source_creator(source.Source())

        elif option == "edit":
            source.edit_source()

        elif option == "delete":
            source.delete_source()

        elif option == "list":
            source.list_sources(pause_after=1)

        elif option == "test":
            test_source()

        else:
            print(f"'{option}' not implemented.")
Exemple #2
0
def tasks():
    while True:
        option = prompts.prompt_options(get_msg("Choose a Task Option"), [
            "new", "edit", "delete", None, "list", "test", "prime", None,
            "back to menu"
        ],
                                        print_options=False,
                                        menu_style=True,
                                        menu_title=get_title("Tasks"))

        if option == "new":
            task.task_creator(task.Task())

        elif option == "edit":
            task.edit_task()

        elif option == "delete":
            task.delete_task()

        elif option == "list":
            task.list_tasks(pause_after=1)

        elif option == "test":
            test_task()

        elif option == "prime":
            prime_task()

        elif option == "back to menu":
            return

        else:
            print(f"'{option}' not implemented.")
Exemple #3
0
def notif_agents():
    while True:
        option = prompts.prompt_options(
            get_msg("Choose a Notification Agent Option"), [
                "new", "edit", "delete", None, "list", "test", None,
                "back to menu"
            ],
            print_options=False,
            menu_style=True,
            menu_title=get_title("Notification Agents"))

        if option == "new":
            notif_agent.notif_agent_creator(notif_agent.NotifAgent(), )

        elif option == "edit":
            notif_agent.edit_notif_agent()

        elif option == "delete":
            notif_agent.delete_notif_agent()

        elif option == "list":
            notif_agent.list_notif_agents(pause_after=1)

        elif option == "test":
            test_notif_agent()

        elif option == "back to menu":
            return

        else:
            print(f"'{option}' not implemented.")
def source_creator(source):
    from lib.core.state import State

    s = source
    sources = State.get_sources()
    modules = State.get_source_modules()

    while True:
        name = s.name
        s.name = creator.prompt_string("Name", default=name)

        s.module = create_source_choose_module(s.module)

        module = modules[s.module]
        props = module.get_properties()
        print("Module Properties")
        for p in props:
            default = None
            if s.module_properties is not None:
                default = s.module_properties.get(p, None)

            if s.module_properties is None:
                s.module_properties = {}

            s.module_properties[p] = creator.prompt_string(f"{p}",
                                                           default=default)

        print()
        print(f"Id: {s.id}")
        print(f"Name: {s.name}")
        print(f"Module: {s.module}")
        print("-----------------------------")
        for p in s.module_properties:
            print(f"{p}: {s.module_properties[p]}")
        print("-----------------------------")

        while True:
            confirm = creator.prompt_options("Choose an option",
                                             ["save", "edit", "test", "quit"])
            if confirm == "test":
                test_source(source, modules)
                continue

            else:
                break

        if confirm == "save":
            break
        elif confirm == "edit":
            continue
        elif confirm == "quit":
            return

    sources[source.id] = source

    save()
Exemple #5
0
def start():
    while True:
        option = prompts.prompt_options(
            get_msg("Choose a Category"),
            ["tasks", "sources", "notification agents", None, "quit"],
            print_options=False,
            menu_style=True,
            menu_title=get_title("Categories"))

        if option == "tasks":
            tasks()

        elif option == "sources":
            sources()

        elif option == "notification agents":
            notif_agents()

        elif option == "quit":
            return

        else:
            print(f"'{option}' not implemented.")
Exemple #6
0
def task_creator(task):
    from lib.core.state import State
    cur_tasks = State.get_tasks()
    sources = State.get_sources()
    notif_agents = State.get_notif_agents()

    t = task

    while True:
        while True:
            print(f"Id: {t.id}")
            t.name = creator.prompt_string("Name", default=t.name)
            t.frequency = creator.prompt_num("Frequency", default=t.frequency)
            t.frequency_unit = creator.prompt_options("Frequency Unit",
                                                      ["minutes", "hours"],
                                                      default=t.frequency_unit)
            t.source_ids = create_task_add_sources(default=t.source_ids)
            if t.source_ids == None:
                return
            t.include = creator.prompt_string(
                "Include [list seperated by commas]",
                allow_empty=True,
                default=t.include)
            t.exclude = creator.prompt_string(
                "Exclude [list seperated by commas]",
                allow_empty=True,
                default=t.exclude)
            t.notif_agent_ids = create_task_add_notif_agents(
                default=t.notif_agent_ids)
            if t.notif_agent_ids == None:
                return

            print()
            print(f"Name: {t.name}")
            print(f"Frequency: {t.frequency} {t.frequency_unit}")
            print(f"Sources")
            print(f"----------------------------")
            for source_id in t.source_ids:
                print(f"{sources[source_id].name}")
            print("-----------------------------")
            print(f"Include: {t.include}")
            print(f"Exclude: {t.exclude}")

            while True:
                confirm = creator.prompt_options(
                    "Choose an option", ["save", "edit", "dryrun", "quit"])
                if confirm == "quit":
                    if creator.yes_no("Quit without saving?", "n") == "y":
                        return
                    else:
                        continue
                elif confirm == "dryrun":
                    if creator.yes_no("Execute dry run?", "y"):
                        log.debug_print("Executing dry run...")
                        test(task)

                    continue
                else:
                    break

            if confirm == "save":
                break
            elif confirm == "edit":
                continue

        cur_tasks[task.id] = task
        save()

        if creator.yes_no("Prime this task?", "y") == "y":
            recent = int(
                creator.prompt_num(
                    "How many of the latest ads do you want notified?",
                    default="3"))
            if recent == 0:
                notify = False
            else:
                notify = True

            prime(task, notify=notify, recent_ads=recent)

        if not cron.exists(task.frequency, task.frequency_unit):
            if creator.yes_no(
                    f"Add cronjob for '{task.frequency} {task.frequency_unit}'",
                    "y") == "y":
                refresh_cron()

        else:
            print(
                f"Cronjob already exists for '{task.frequency} {task.frequency_unit}'... skipping"
            )

        print("Done!")
        return
Exemple #7
0
def notif_agent_creator(notif_agent):
    from lib.core.state import State

    n = notif_agent

    cur_notif_agents = State.get_notif_agents()
    modules = State.get_notif_agent_modules()

    while True:
        n.name = creator.prompt_string("Name", default=n.name)
        n.module = create_notif_agent_choose_module(n.module)

        module = modules[n.module]
        props = module.get_properties()

        print("Module Properties")

        for p in props:
            default = None
            if n.module_properties is not None:
                default = n.module_properties.get(p, None)
            else:
                n.module_properties = {}

            while True:
                n.module_properties[p] = creator.prompt_string(f"{p}",
                                                               default=default)
                is_valid, error_msg = module.is_property_valid(
                    p, n.module_properties[p])

                if is_valid:
                    break
                else:
                    print(error_msg)
                    default = None
        print()
        print(f"Id: {n.id}")
        print(f"Name: {n.name}")
        print(f"Module: {n.module}")
        print("-----------------------------")
        for p in props:
            print(f"{p}: {n.module_properties[p]}")
        print("-----------------------------")

        while True:
            confirm = creator.prompt_options("Choose an option",
                                             ["save", "edit", "test", "quit"])
            if confirm == "test":
                test_notif_agent(notif_agent)
                continue
            else:
                break

        if confirm == "save":
            break
        elif confirm == "edit":
            continue
        elif confirm == "quit":
            return

    cur_notif_agents[n.id] = notif_agent

    State.save_notif_agents()