示例#1
0
def prompt() -> Optional[booklog_api.AuthorWithWorks]:
    name = None

    while name is None:
        name = ask.prompt("Author: ")

    authors = booklog_api.search_authors(name)

    options: list[AuthorOption] = build_author_options(authors)

    selected_author = None

    while selected_author is None:

        selected_author = radio_list.prompt(
            title="Select author:",
            options=options,
        )

        if selected_author is None:
            break

    if not selected_author:
        return None

    if confirm("{0}?".format(selected_author.name)):
        return selected_author

    return prompt()
示例#2
0
def ask_for_progress() -> str:
    validator = Validator.from_callable(
        is_valid_progress,
        error_message=
        'Must be a whole number (no % sign), F for "Finished", or A for "Abandoned"',
        move_cursor_to_end=True,
    )

    progress = ask.prompt(
        "Progress: ",
        validator=validator,
        default="",
        rprompt=
        'Whole number (no % sign), F for "Finished", or A for "Abandoned"',
    )

    if progress:
        if progress == "F":
            return "Finished"

        if progress == "A":
            return "Abandoned"

        return "{0}%".format(progress)

    return ask_for_progress()
示例#3
0
def prompt() -> Optional[booklog_api.WorkWithAuthors]:
    title = None

    while title is None:
        title = ask.prompt("Title: ")

    works = booklog_api.search_works(title)

    options: list[WorkOption] = build_work_options(works)

    selected_work = None

    while selected_work is None:

        selected_work = radio_list.prompt(
            title="Select work:",
            options=options,
        )

        if selected_work is None:
            break

    if not selected_work:
        return None

    if confirm("{0}?".format(selected_work.title)):
        return selected_work

    return prompt()
示例#4
0
def ask_for_name() -> Optional[str]:
    name = ask.prompt("Name: ")

    if not name:
        return None

    if confirm(name):  # noqa: WPS323
        return name

    return ask_for_name()
示例#5
0
def ask_for_title() -> Optional[str]:
    title = ask.prompt("Title: ")

    if not title:
        return None

    if confirm(title):  # noqa: WPS323
        return title

    return ask_for_title()
示例#6
0
def ask_for_year() -> Optional[str]:
    year = ask.prompt("Year First Published: ")

    if not year:
        return None

    if confirm(year):  # noqa: WPS323
        return year

    return ask_for_year()
示例#7
0
def ask_for_subtitle() -> Optional[str]:
    subtitle = ask.prompt("Sub-title: ")

    if not subtitle:
        return None

    if confirm(subtitle):  # noqa: WPS323
        return subtitle

    return ask_for_subtitle()
示例#8
0
def ask_for_grade() -> Optional[str]:
    validator = Validator.from_callable(
        is_grade,
        error_message="Must be a valid grade.",
        move_cursor_to_end=True,
    )

    review_grade = ask.prompt("Grade: ", validator=validator, default="")

    if not review_grade:
        return None

    if confirm(review_grade):  # noqa: WPS323
        return review_grade

    return ask_for_grade()
示例#9
0
def ask_for_authors() -> list[booklog_api.WorkAuthor]:
    work_authors: list[booklog_api.WorkAuthor] = []

    while True:
        author = ask_for_author.prompt()

        if author:
            author_notes = ask.prompt("Notes: ")

            if not author_notes:
                author_notes = None

            work_authors.append(
                booklog_api.WorkAuthor(slug=author.slug, notes=author_notes))

        if not confirm("Add more?"):
            return work_authors
示例#10
0
def ask_for_date() -> Optional[date]:
    validator = Validator.from_callable(
        is_date,
        error_message="Must be a valid date in YYYY-MM-DD format.",
        move_cursor_to_end=True,
    )

    date_string = ask.prompt(
        "Date: ",
        rprompt="YYYY-MM-DD format.",
        validator=validator,
        default=date.today().strftime("%Y-%m-%d"),  # noqa: WPS323
    )

    if not date_string:
        return None

    given_date = string_to_date(date_string)

    if confirm(given_date.strftime("%A, %B, %-d, %Y?")):  # noqa: WPS323
        return given_date

    return ask_for_date()
示例#11
0
def new_edition() -> Optional[str]:
    return ask.prompt("Edition: ")