Пример #1
0
def getMenuSelection(menu: dict) -> int:
    """
    Gets user selection of menu item.

    It shows the menu, receives user's input,
    validates if the input is correct and return the
    input.

    Parameters
    ----------
    menu: dict
        The menu to be displayed.
    """
    validSelection = False
    selections = menu.keys()
    selection = None
    __displayMenu(menu)
    while not validSelection:
        try:
            selection = int(input("Enter your selection >> "))
            if selection not in selections:
                console.print(":cross_mark: Invalid selection", style="danger")
            else:
                validSelection = True
        except ValueError as err:
            console.print(":cross_mark: Invalid selection", style="danger")
    return selection
Пример #2
0
def logout():
    """
    User logout. 
    """
    global USER_VERIFIED
    USER_VERIFIED = False
    console.print("Successfully logged out", style="success")
Пример #3
0
def displayAccountDetails(accounts: [dict]) -> None:
    """
    Displays account detail in a table.

    A row is a record of an account. It contains information like
    account_type, account_number, balance etc. These are the table
    column. ``accounts`` can contain multiple record.

    The table column and rows are created dynamically.

    Parameters
    accounts: [dict]
        A list of dictionary that contains information about multiple accounts.
    ---------
    """
    table = Table(title="Account details")
    # Get one record to extract the column names
    columns = accounts[0].keys()
    # Add all column heading to ``table``
    for column in columns:
        table = addTableColumnHeading(table, column, columnStyle)

    # Add rows to table
    for account in accounts:
        # take each value and convert it to string and put it in the list
        row = [str(elem) for elem in list(account.values())]
        table.add_row(*row)
    console.print(table)
Пример #4
0
def displayAsTable(data: dict,
                   title: str = "Sample Table",
                   columnStyle: dict = None,
                   rowStyle: dict = None):
    """

    The first row of the data must contain column names.

    Parameters
    ----------
    columnStyle: dict
        It is a dictionary where each item contains some
        styling information. The key is the table column name.
        It must match with column name. The value is another dictionary.

        style: dict
            This contains style information. The available options are-
            justify: (left, center, right, full)
            style: (color, bold)
            no_wrap: True/False

    """
    table = Table(title=title)
    columns = data[0].keys()
    for column in columns:
        if columnStyle != None:
            style = columnStyle[column]
            table = addTableColumnHeading(table, column, style)
        else:
            table = addTableColumnHeading(table, column)
    for item in data:
        row = [str(elem) for elem in list(item.values())]
        table.add_row(*row)
    console.print(table)
Пример #5
0
def __displayMenu(menu: dict):
    console.print("[AVAILABLE COMMANDS] >> ",
                  style="bold white on green ",
                  end="\t")
    for key in menu:
        console.print(menu[key], style="bold blue underline", end="\t")
    print("", end="\n")
Пример #6
0
def viewTransactions() -> None:
    selectedAccount = chooseAccount()
    transactions = TransactionDB.getAllTransactions(selectedAccount)
    if transactions:
        displayAsTable(data=transactions, title="Transaction Details")
    else:
        console.print("There is no transaction in this account",
                      style="danger")
Пример #7
0
def login():
    email = pyip.inputStr("Enter your email address: ")
    password = getpass("Enter your password: "******"Successfully logged in :thumbs_up:", style="success")
    else:
        console.print(":cross_mark: Login failed", style="danger")
Пример #8
0
def getListSelection(items: list) -> int:
    """
    Gets user selection of a list of items.

    It can be printed as ordered or unordered list
    """
    #TODO: return error if not list
    validSelection = False
    selection = None
    while not validSelection:
        __displayList(items)
        selection = int(input("Enter your selection >> "))
        if selection < 1 and selection > len(items):
            console.print(":cross_mark: Invalid selection", style="danger")
        else:
            validSelection = True
    return selection
Пример #9
0
def showGreetings():
    if os.name == 'nt':
        os.system('cls')
    else:
        os.system('clear')
    console.print("WELCOME TO CONSOLE BANK",
                  style="bold white on blue",
                  justify="center")
    console.print()
    console.print()
    console.print()
Пример #10
0
def signUp():
    """
    Creates an user.

    Takes user input from console, validates input and send to database.
    """
    #get the data
    fname = getInputStr(prompt="Enter your first name: ",
                        maxlength=FNAME_LENGTH,
                        regex=None)
    lname = getInputStr(prompt="Enter your last name: ",
                        maxlength=LNAME_LENGTH,
                        regex=None)
    street = getInputStr(prompt="Enter your street number and name: ",
                         maxlength=STREET_LENGTH,
                         regex=None)
    city = getInputStr(prompt="Which city do you live in? ",
                       maxlength=CITY_LENGTH,
                       regex=None)
    post = getInputStr(prompt="What is your post code? ",
                       maxlength=POST_LENGTH,
                       regex=None)
    phone = getInputStr(prompt="What is your phone number? ",
                        maxlength=PHONE_LENGTH,
                        regex=PHONE_REGEX)
    email = getInputStr(prompt="What is your email address? ",
                        maxlength=EMAIL_LENGTH,
                        regex=EMAIL_REGEX)
    password = getNewPassword()

    #Send to database
    itemid = UserDB.createUser({
        "fname": fname,
        "lname": lname,
        "street": street,
        "city": city,
        "post": post,
        "phone": phone,
        "email": email,
        "password": password
    })
    if itemid != None:
        console.print("Account successfully created!", style="success")
Пример #11
0
def getInputInt(prompt: str = None, acceptedValue: list = None):
    """
    Get an integer input from user. 

    If ``acceptedValue`` is given, it matches user input
    against it and prompts until a valid selection is made.
    """
    validSelection = False
    if validSelection != None:
        while not validSelection:
            try:
                selection = int(input(prompt))
                if selection in acceptedValue:
                    validSelection = True
                    break
            except ValueError as err:
                console.print("Invalid selection\n", style="bold red")
            else:
                console.print("Invalid selection\n", style="bold red")
    return selection
Пример #12
0
def exit():
    global exitProgram
    exitProgram = True
    console.print("Thank you for choosing Console Bank", style="bold green")