Пример #1
0
def display_menu():
    '''Function to display the main menu'''
    answer = questionary.select(
        "What do you want to do?",
        choices=[
            Separator('---- NMAP ---'),
            Choice('Nmap (fast)', "NmapModule.fast_scan()"),
            Choice('Nmap (full)', "NmapModule.full_scan()"),
            Choice('Nmap (fast + full)', "NmapModule.fast_full_scan()"),
            Separator('----- SCAN -----'),
            Choice('Internet archives fast scan',
                   "ScanModule.get_internet_archives()"),
            Choice('Internet archives full scan (dump all links recursively)',
                   "ScanModule.get_internet_archives(True)"),
            Choice('SSL Scan (Qualys)', "ScanModule.get_ssl_scan()"),
            Separator('----- WAF -----'),
            Choice('wafw00f scan', "WafModule.start_wafw00f_scan()"),
            Separator('----- OSINT -----'),
            Choice('Shodan scan', "OsintModule.start_shodan_scan()"),
            Separator('----- WEBFUZZ -----'),
            Choice('GoBuster Directories Web Fuzz (GET)',
                   "GoBusterModule.start_webfuzz()")
        ]).ask()

    exec(answer)
def second_question_batch(path):
    # ask to rate books based on the class
    # RETURNS: PANDAS DF

    # initialize a dataframe for storing the results
    user_ratings = pd.DataFrame(columns=('book_id', 'user_rating'))

    # read in the correct csv file
    books_to_rate = pd.read_csv(path)

    # loop over the books in a premade dataset for a class
    for i in range(0, len(books_to_rate)):
        answer = questionary.select(
            '\n\n Rate the book "' + books_to_rate['book_title'].iloc[i] +
            '" by ' + books_to_rate['author_name'].iloc[i] + "\n\n",
            choices=[
                Separator(), '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
                'Not read',
                Separator()
            ]).ask()
        # add the results to a dataframe
        answer = answer if answer != 'Not read' else 0
        user_ratings.loc[i] = [books_to_rate['book_id'].iloc[i], answer]

    return (user_ratings)
def first_question_batch():
    # ask for age and education
    # RETURNS: DICT
    questions = [{
        'type':
        'select',
        'name':
        'age',
        'message':
        '\nWhat is Your age?\n',
        'choices': [
            Separator(), '0 - 12', '12 - 18', '18 - 25', '25 - 45', '45+',
            Separator()
        ]
    }, {
        'type':
        'select',
        'name':
        'education',
        'message':
        '\nWhat is Your education level?\n',
        'choices':
        [Separator(), 'primary', 'high school', 'university',
         Separator()]
    }]
    return prompt(questions)
Пример #4
0
def test_separator_up():
    message = 'Foo message'
    kwargs = {'choices': ['foo', Separator(), 'bazz', Separator("--END--")]}
    text = KeyInputs.UP + KeyInputs.UP + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input('select', message, text, **kwargs)
    assert result == 'foo'
Пример #5
0
def test_separator_up():
    message = "Foo message"
    kwargs = {"choices": ["foo", Separator(), "bazz", Separator("--END--")]}
    text = KeyInputs.UP + KeyInputs.UP + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input("select", message, text, **kwargs)
    assert result == "foo"
Пример #6
0
def ask_dictstyle(**kwargs):
    questions = [{
        "type":
        "checkbox",
        "qmark":
        "😃",
        "message":
        "Select toppings",
        "name":
        "toppings",
        "choices": [
            {
                "name": "foo",
                "checked": True
            },
            Separator(),
            {
                "name": "bar",
                "disabled": "nope"
            },
            "bazz",
            Separator("--END--"),
        ],
    }]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #7
0
def modify_choice(logger, settings, config_path):
    options = []
    for k, v in settings.items():
        options.append(Separator())
        if k == 'config_name':
            options.append(f'{k} - Current setting: {v}')
        else:
            for inner_k, inner_v in v.items():
                if inner_k == 'sql_table':
                    options.append(Separator())
                options.append(f'{inner_k} - Current setting: {inner_v}')
    print('Which setting do you need to modify?')
    exit_no_save = 'Exit without saving changes'
    exit_save = 'Exit and save'
    if exit_no_save not in options:
        exit_list = [exit_save, exit_no_save, Separator()]
        options = exit_list + options
    to_modify = questionary.select("Select an option to modify:", choices=options).ask()
    to_modify = to_modify.split('-')[0].strip()
    if to_modify == exit_save:
        with open(config_path, 'w') as file:
            updated_config = yaml.dump(settings, default_flow_style=False, sort_keys=False)
            updated_config = updated_config.replace('-', '')
            updated_config = updated_config.replace('null', '')
            file.write(updated_config.replace('-', ''))
        logger.info('All done. Re run the tool to use your new configuration. ')
        sys.exit()
    elif to_modify == exit_no_save:
        logger.info('Changes discarded.')
        sys.exit()
    elif not to_modify:
        modify_choice(logger, settings, config_path)
    else:
        update_key(logger, settings, to_modify)
        modify_choice(logger, settings, config_path)
Пример #8
0
def test_separator_up():
    message = 'Foo message'
    kwargs = {'choices': ['foo', Separator(), 'bazz', Separator("--END--")]}
    text = (KeyInputs.UP + KeyInputs.UP + KeyInputs.SPACE + KeyInputs.ENTER +
            "\r")

    result, cli = feed_cli_with_input('checkbox', message, text, **kwargs)
    assert result == ["foo"]
Пример #9
0
def test_separator_up():
    message = "Foo message"
    kwargs = {"choices": ["foo", Separator(), "bazz", Separator("--END--")]}
    # UP and `k` should do the same
    text = KeyInputs.UP + "k" + KeyInputs.SPACE + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
    assert result == ["foo"]
Пример #10
0
def test_invalid_shortcuts():
    message = 'Foo message'
    kwargs = {
        'choices': [
            {"name": "foo", "key": "asd"},
            Separator(),
            {"name": "bar", "key": "1"},
            'bazz',
            Separator("--END--")]
    }
    text = "1" + KeyInputs.ENTER + "\r"

    with pytest.raises(ValueError):
        feed_cli_with_input('rawselect', message, text, **kwargs)
Пример #11
0
def test_select_invert():
    message = "Foo message"
    kwargs = {
        "choices": [
            {"name": "foo", "checked": True},
            Separator(),
            {"name": "bar", "disabled": "nope"},
            "bazz",
            Separator("--END--"),
        ]
    }
    text = KeyInputs.UP + "i" + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
    assert result == ["bazz"]
Пример #12
0
def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.checkbox('Select toppings',
                                    qmark='😃',
                                    choices=[
                                        Choice("foo", checked=True),
                                        Separator(),
                                        Choice("bar", disabled="nope"), 'bazz',
                                        Separator("--END--")
                                    ],
                                    style=custom_style_dope,
                                    **kwargs)

    # prompt the user for an answer
    return question.ask()
Пример #13
0
def ask_dictstyle(**kwargs):
    questions = [
        {
            "type": "confirm",
            "name": "conditional_step",
            "message": "Would you like the next question?",
            "default": True,
        },
        {
            "type": "text",
            "name": "next_question",
            "message": "Name this library?",
            # Validate if the first question was answered with yes or no
            "when": lambda x: x["conditional_step"],
            # Only accept questionary as answer
            "validate": lambda val: val == "questionary",
        },
        {
            "type": "select",
            "name": "second_question",
            "message": "Select item",
            "choices": ["item1", "item2",
                        Separator(), "other"],
        },
        {
            "type": "text",
            # intentionally overwrites result from previous question
            "name": "second_question",
            "message": "Insert free text",
            "when": lambda x: x["second_question"] == "other",
        },
    ]
    return prompt(questions)
Пример #14
0
def test_separator_down():
    message = 'Foo message'
    kwargs = {'choices': ['foo', Separator(), 'bazz']}
    text = KeyInputs.DOWN + KeyInputs.SPACE + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input('checkbox', message, text, **kwargs)
    assert result == ["bazz"]
Пример #15
0
def test_separator_down():
    message = "Foo message"
    kwargs = {"choices": ["foo", Separator(), "bazz"]}
    text = KeyInputs.DOWN + KeyInputs.SPACE + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
    assert result == ["bazz"]
Пример #16
0
def test_separator_shortcuts():
    message = "Foo message"
    kwargs = {"choices": ["foo", Separator(), "bazz"]}
    text = "2" + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input("rawselect", message, text, **kwargs)
    assert result == "bazz"
Пример #17
0
def test_select_initial_choice_not_selectable():
    message = "Foo message"
    separator = Separator()
    kwargs = {"choices": ["foo", "bazz", separator], "default": separator}
    text = KeyInputs.ENTER + "\r"

    with pytest.raises(ValueError):
        feed_cli_with_input("select", message, text, **kwargs)
Пример #18
0
def test_select_all():
    message = 'Foo message'
    kwargs = {
        'choices': [{
            "name": "foo",
            "checked": True
        },
                    Separator(), {
                        "name": "bar",
                        "disabled": "nope"
                    }, 'bazz',
                    Separator("--END--")]
    }
    text = KeyInputs.UP + "a" + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input('checkbox', message, text, **kwargs)
    assert result == ["foo", "bazz"]
Пример #19
0
def test_separator_shortcuts():
    message = 'Foo message'
    kwargs = {
        'choices': ['foo', Separator(), 'bazz']
    }
    text = "2" + KeyInputs.ENTER + "\r"

    result, cli = feed_cli_with_input('rawselect', message, text, **kwargs)
    assert result == 'bazz'
Пример #20
0
def test_invalid_shortcuts():
    message = "Foo message"
    kwargs = {
        "choices": [
            {
                "name": "foo",
                "key": "asd"
            },
            Separator(),
            {
                "name": "bar",
                "key": "1"
            },
            "bazz",
            Separator("--END--"),
        ]
    }
    text = "1" + KeyInputs.ENTER + "\r"

    with pytest.raises(ValueError):
        feed_cli_with_input("rawselect", message, text, **kwargs)
Пример #21
0
def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.rawselect('What do you want to do?',
                                     choices=[
                                         'Order a pizza', 'Make a reservation',
                                         Separator(), 'Ask opening hours',
                                         'Talk to the receptionist'
                                     ],
                                     style=custom_style_dope,
                                     **kwargs)

    # prompt the user for an answer
    return question.ask()
Пример #22
0
def ask_dictstyle(**kwargs):
    questions = [{
        'type':
        'checkbox',
        'qmark':
        '😃',
        'message':
        'Select toppings',
        'name':
        'toppings',
        'choices': [{
            "name": "foo",
            "checked": True
        },
                    Separator(), {
                        "name": "bar",
                        "disabled": "nope"
                    }, 'bazz',
                    Separator("--END--")]
    }]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #23
0
def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.select('What do you want to do?',
                                  qmark='😃',
                                  choices=[
                                      'Order a pizza', 'Make a reservation',
                                      Separator(), 'Ask for opening hours',
                                      Choice(
                                          'Contact support',
                                          disabled='Unavailable at this time'),
                                      'Talk to the receptionist'
                                  ],
                                  style=custom_style_dope,
                                  **kwargs)

    # prompt the user for an answer
    return question.ask()
Пример #24
0
def ask_dictstyle(**kwargs):
    questions = [
        {
            'type': 'rawselect',
            'name': 'theme',
            'message': 'What do you want to do?',
            'choices': [
                'Order a pizza',
                'Make a reservation',
                Separator(),
                'Ask opening hours',
                'Talk to the receptionist'
            ]
        },
    ]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #25
0
def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.rawselect(
        "What do you want to do?",
        choices=[
            "Order a pizza",
            "Make a reservation",
            Separator(),
            "Ask opening hours",
            "Talk to the receptionist",
        ],
        style=custom_style_dope,
        **kwargs,
    )

    # prompt the user for an answer
    return question.ask()
Пример #26
0
def ask_dictstyle(**kwargs):
    questions = [{
        'type':
        'select',
        'name':
        'theme',
        'message':
        'What do you want to do?',
        'choices': [
            'Order a pizza', 'Make a reservation',
            Separator(), 'Ask for opening hours', {
                'name': 'Contact support',
                'disabled': 'Unavailable at this time'
            }, 'Talk to the receptionist'
        ]
    }]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #27
0
def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.select(
        "What do you want to do?",
        qmark="😃",
        choices=[
            "Order a pizza",
            "Make a reservation",
            Separator(),
            "Ask for opening hours",
            Choice("Contact support", disabled="Unavailable at this time"),
            "Talk to the receptionist",
        ],
        style=custom_style_dope,
        **kwargs,
    )

    # prompt the user for an answer
    return question.ask()
Пример #28
0
def ask_dictstyle(**kwargs):
    questions = [
        {
            "type":
            "rawselect",
            "name":
            "theme",
            "message":
            "What do you want to do?",
            "choices": [
                "Order a pizza",
                "Make a reservation",
                Separator(),
                "Ask opening hours",
                "Talk to the receptionist",
            ],
        },
    ]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #29
0
def ask_dictstyle(**kwargs):
    questions = [{
        "type":
        "select",
        "name":
        "theme",
        "message":
        "What do you want to do?",
        "choices": [
            "Order a pizza",
            "Make a reservation",
            Separator(),
            "Ask for opening hours",
            {
                "name": "Contact support",
                "disabled": "Unavailable at this time"
            },
            "Talk to the receptionist",
        ],
    }]

    return prompt(questions, style=custom_style_dope, **kwargs)
Пример #30
0
def ask_user_config() -> Dict[str, Any]:
    """
    Ask user a few questions to build the configuration.
    Interactive questions built using https://github.com/tmbo/questionary
    :returns: Dict with keys to put into template
    """
    questions = [
        {
            "type": "confirm",
            "name": "dry_run",
            "message": "Do you want to enable Dry-run (simulated trades)?",
            "default": True,
        },
        {
            "type": "text",
            "name": "stake_currency",
            "message": "Please insert your stake currency:",
            "default": 'BTC',
        },
        {
            "type": "text",
            "name": "stake_amount",
            "message": "Please insert your stake amount:",
            "default": "0.01",
            "validate": lambda val: val == UNLIMITED_STAKE_AMOUNT or validate_is_float(val),
        },
        {
            "type": "text",
            "name": "max_open_trades",
            "message": f"Please insert max_open_trades (Integer or '{UNLIMITED_STAKE_AMOUNT}'):",
            "default": "3",
            "validate": lambda val: val == UNLIMITED_STAKE_AMOUNT or validate_is_int(val)
        },
        {
            "type": "text",
            "name": "ticker_interval",
            "message": "Please insert your timeframe (ticker interval):",
            "default": "5m",
        },
        {
            "type": "text",
            "name": "fiat_display_currency",
            "message": "Please insert your display Currency (for reporting):",
            "default": 'USD',
        },
        {
            "type": "select",
            "name": "exchange_name",
            "message": "Select exchange",
            "choices": [
                "binance",
                "binanceje",
                "binanceus",
                "bittrex",
                "kraken",
                Separator(),
                "other",
            ],
        },
        {
            "type": "autocomplete",
            "name": "exchange_name",
            "message": "Type your exchange name (Must be supported by ccxt)",
            "choices": available_exchanges(),
            "when": lambda x: x["exchange_name"] == 'other'
        },
        {
            "type": "password",
            "name": "exchange_key",
            "message": "Insert Exchange Key",
            "when": lambda x: not x['dry_run']
        },
        {
            "type": "password",
            "name": "exchange_secret",
            "message": "Insert Exchange Secret",
            "when": lambda x: not x['dry_run']
        },
        {
            "type": "confirm",
            "name": "telegram",
            "message": "Do you want to enable Telegram?",
            "default": False,
        },
        {
            "type": "password",
            "name": "telegram_token",
            "message": "Insert Telegram token",
            "when": lambda x: x['telegram']
        },
        {
            "type": "text",
            "name": "telegram_chat_id",
            "message": "Insert Telegram chat id",
            "when": lambda x: x['telegram']
        },
    ]
    answers = prompt(questions)

    if not answers:
        # Interrupted questionary sessions return an empty dict.
        raise OperationalException("User interrupted interactive questions.")

    return answers