def pick_url(options, allow_custom_input=False):
    """Allows the user to pick one of the options or enter a new locaiton"""

    term = get_term()

    puts(
        "Please choose one of the following options: ")

    index = 1
    enter_custom_choice = 1
    default_choice = 1

    for option in options:
        if(option.priority < 1):
            puts(' (%d) %s ' % (index, term.red(option.url)))
            if(default_choice == index):
                default_choice += 1
        else:
            to_print = ' (%d) %s ' % (index, option.url)

            if(index == default_choice):
                to_print = term.green(to_print)
            puts(to_print)
        index += 1

    enter_custom_choice = len(options) + 1

    if allow_custom_input:
        puts(' (%d) enter a new location' % index)

    def option_to_str(i):
        if not i == default_choice:
            return str(i)
        else:
            return str(i) + "=default"

    if allow_custom_input:
        choices = map(
            option_to_str,
            range(1, index + 1)
        )
    else:
        choices = map(
            option_to_str,
            range(1, index)
        )

    while True:

        url = None

        choice = raw_input(
            "Make your choice (%s): " % (
                ",".join(choices),
            )
        )

        selected = None

        if choice == "":
            selected = default_choice
        elif choice in choices:
            selected = choice

            try:
                selected = int(choice)
            except ValueError:
                selected = None

        elif choice == str(default_choice):
            selected = default_choice

        if selected:
            if allow_custom_input and selected == enter_custom_choice:
                url = enter_url()
            else:
                url = options[selected-1].url

            if url:
                return url
dataset/ETHPy150Open wercker/wercker-cli/werckercli/cli.py/pick_url/original