-1

I am currently doing project for college where I need to create a basic banking system using google sheets & python. I have successfully been able to add customer data & check data is correct. However I am looking to see how i could check a specific customer balance depending on their email address.

Email Address Full Name Password Balance
brian_smith@outlook.com brian Smith Password1234 500

Here is my code.

def emailcheck(emailinput):
    """
    Email validator function
    """
    try:
        valid = validate_email(emailinput)
        emailinput = valid.email
        return emailinput
    except EmailNotValidError as e:
        print("The email you provided is not valid please try again\n")



def registerEmail():
    """
    This fucntion checks the email address is correct 
    while loop will continue until a valid emai is input
    """

    print("Welcome to retro bank As a new customer\n" +
        "Please complete the following fileds to sign up for an account\n")

    while True:
        try:
            global email
            email = input("Please enter your email address: ")
            einput = emailcheck(email)
            if einput != email:
                raise ValueError(
                    "Please enter a valid email" +
                    f" you entered: {email}"
                )
            else:
                regDetails()
                return email
        except ValueError as e:
            print(f"Invalid data: {e}, please try again.\n")



def regDetails():

    sheet = SHEET.worksheet("customer-data")
    new_cust = []
    bonus = 500

    
    while True:
        name = input("Please enter your full name: ")
        password = input("Please enter your password: ")
        if name == "":
            print("Name is required")
        elif password == "":
            print("Password Required")
        else:
            new_cust.append(email)
            new_cust.append(name)
            new_cust.append(password)
            new_cust.append(bonus)
            sheet.append_row(new_cust)
            print("WELCOME TO RETRO BANK !" +
            " As a new customer you will receive £500 joining bonus")
            login()
            break



def login():
    """
    This fucntion will allow the exisiting user 
    log into their bank account
    """
    global email_ver
    global details
    global password
    global balances
    email_ver = SHEET.worksheet("customer-data")
    details = email_ver.col_values(1)
    password = email_ver.col_values(3)
    balances = email_ver.col_values(4)
    user = []

    while True:
        ename = input("Please enter your email address: ")
        epass = input("Please enter your password: ")
        if ename  == "":
            print("Name is required")
        elif epass == "":
            print("Password Required")
        else:
            break

    user.append(ename)
    user.append(epass)

    found = 0

    for i in zip(details, password):
        if i == tuple(user):
            found = 1
            print("Successfully Verified")
            mainDash(user)
            return found
    if found == 0:
        print("The username or the password you provided might be wrong.\n")
        login()
        return found


def mainDash(user):
    print(user)
    print("WELCOME")

    for i in (details):
        if i == user:
            print()
Edo Akse
  • 4,051
  • 2
  • 10
  • 21

1 Answers1

0

Reading the documentation helps, as stated by Ethan J.

See below for a simple function that returns the row containing the user as a list. Returns None if user not found. Note that this function is case sensitive in the input.

Note, you might need to offset the returned row by 1. Try it and see if it returns the correct row.

def find_user(sheet, email):
    emails = sheet.col_values(1)
    if email in emails:
        # https://docs.gspread.org/en/latest/user-guide.html#getting-all-values-from-a-row-or-a-column
        return sheet.row_values(emails.index(email))
    else:
        return None
Edo Akse
  • 4,051
  • 2
  • 10
  • 21