def main():
    # define the time to show in output
    now = datetime.now()
    current_time = now.strftime("%m/%d/%Y  %H:%m")

    # Searches for the Account file to open, we are using json in this module since it has the latest balance information
    acct_name = input("Please enter the username for your account: ")
    # try except method to catch a FileNot Found Error
    try:
        with open(
                os.path.join(
                    "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                    "%s.json" % acct_name), 'r') as acct_information:
            balance_info = json.load(acct_information)
            acct_number = input("Please enter the account number: ")
            if acct_number in balance_info['Account Number ']:
                print("Current balance as of " + current_time + " is " +
                      "${:,.2f}.".format(balance_info['Balance ']))
                usermenu.main()
                logging.info("User " + acct_name + " has checked his balance")
            else:
                print("Account Number does not match your account username")
                logging.warning(
                    "Account Number entered does not match the one in record")

    except FileNotFoundError:
        print("No account was found under this username")
        logging.error("ACCOUNT NOT FOUND")
        usermenu.main()
Esempio n. 2
0
def main():
    #MUST CREATE A TRY-EXCEPT THINGY TO CATCH IF THE FILE NAME ISNT FOUND.
    acct_username = input("Please enter the username: "******"C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                           "%s.json" % acct_username), 'r') as read_acct:
            acct_data = json.load(read_acct)
            #print(acct_data['Password '])
            password_prompt = getpass.getpass("Please enter your password: "******" has logged in to the system"))
                    usermenu.main()
                else:
                    print("Wrong password, returning to main menu")
                    logging.error((acct_username + " has entered a wrong password"))
                    menu.main()
            except FileNotFoundError:
                logging.warning("Account Information not found")

    except FileNotFoundError:
        print("The account does not exist, please reenter your username. If you dont have a username you must "
              "register for the service before attempting to log in. Returning to Main Menu")
        logging.error(("Account Username does not exist"))
        menu.main()
    def test_withdraw_form(self):
        now = datetime.now()
        initial_balance_time = now.strftime("%m/%d/%Y")
        with open(
                os.path.join(
                    "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                    "jojo.json"), 'r') as acct_balance:
            balance_info = json.load(acct_balance)
            # Verify the account number before proceeding
            account_number = input(
                "Please verify your identity by entering the account number: ")
            if account_number in balance_info['Account Number ']:
                print("Current balance as of " + initial_balance_time +
                      " is " + "${:,.2f}.".format(balance_info['Balance ']))
                # asks for user input for the amount of money to be withdrawn. IF amount enter exceeds amount in balance, traansaction will be declined
                withdrawn_amount = (float(
                    input("Please enter the amount to be withdrawn: ")))
                if withdrawn_amount <= balance_info['Balance ']:
                    # substract the amount entered from the balance
                    new_balance = balance_info['Balance '] - withdrawn_amount
                    # update json with new balance:
                    with open(
                            os.path.join(
                                "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                                "jojo.json"), 'r+') as balance_withdrawn:
                        balance_update = json.load(balance_withdrawn)
                        balance_update['Balance '] = new_balance
                        balance_withdrawn.seek(0)
                        balance_withdrawn.write(json.dumps(balance_update))
                        balance_withdrawn.truncate()

                    # record the transaction on the text file:
                    history_update = open(
                        os.path.join(
                            "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances",
                            "jojo.txt"), 'a+')
                    history_update.write("\n" + initial_balance_time +
                                         "- Withdrawal - " +
                                         "${:,.2f}.".format(withdrawn_amount))
                    history_update.close()

                    # return the user to the main menu

                else:
                    print(
                        "Overdraft Protection: The transaction you wish to make is unauthorized due to your withdrawal exceeding your available funds"
                    )
                    usermenu.main()
            else:
                print(
                    "The account number does not match, returning to main menu"
                )
 def test_login_password(self):
     with open(
             os.path.join(
                 "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                 'jojo.json'), 'r') as read_acct:
         acct_data = json.load(read_acct)
     password_prompt = input("Please enter your password: "******" has logged in to the system"))
         usermenu.main()
     else:
         print("Wrong password, returning to main menu")
         # logging.error((acct_username + " has entered a wrong password"))
         menu.main()
    def test_transactionhistory_form(self):

        print("The complete transaction history for account")
        # search for file to open
        acct_name = input("Please enter the username for the account: ")
        # try - excpet in case file isnt found
        try:
            with open(
                    os.path.join(
                        "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances",
                        "%s.txt" % acct_name), 'r') as balance_history:
                print(balance_history.read())
                print("Transaction history for " + acct_name)
                print("Thanks for using PygBank.")
                usermenu.main()
        except FileNotFoundError:
            print("Account does not exist. Returning to main menu")
            usermenu.main()
    def test_deposit_form(self):
        now = datetime.now()
        initial_balance_time = now.strftime("%m/%d/%Y")
        with open(
                os.path.join(
                    "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                    "jojo.json"), 'r') as acct_balance:
            balance_info = json.load(acct_balance)
            account_number = input(
                "Please verify your identity by entering the account number: ")
            if account_number in balance_info['Account Number ']:
                print("Current balance as of " + initial_balance_time +
                      " is " + '${:,.2f}'.format(balance_info['Balance ']))
                deposit_amount = (float(
                    input("Please enter the deposit amount: ")))
                if deposit_amount > 0.0:
                    # creating the new balance
                    new_balance = deposit_amount + balance_info['Balance ']

                    # saving to json and
                    with open(
                            os.path.join(
                                "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                                'jojo.json'), 'r+') as balance_update:
                        balance_json = json.load(balance_update)
                        balance_json['Balance '] = new_balance
                        balance_update.seek(0)
                        balance_update.write(json.dumps(balance_json))
                        balance_update.truncate()

                    # Sve to the  transaction history goes here
                    balance_update = open(
                        os.path.join(
                            "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances",
                            "jojo.json"), 'a+')
                    balance_update.write("\n" + initial_balance_time +
                                         "- Deposit - " +
                                         "${:,.2f}.".format(deposit_amount))
                    balance_update.close()
                else:
                    print(
                        "Invalid Amount, please enter an amount higher than 0.Returning to menu"
                    )
                    usermenu.main()
Esempio n. 7
0
def main():
    #defines and sets the time format
    now = datetime.now()
    transfer_time = now.strftime("%m/ %d/ %Y")
    #asks the user for account username. Try exception used to catch a failed login attempt
    acct_name = input("Please enter the account username: "******"C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                             "%s.json" % acct_name), 'r+') as sender_account:
            #verifies the account number is a valid one:
            sender_info = json.load(sender_account)
            account_number = input("Please verify your identity by using the account number: ")
            if account_number in sender_info['Account Number ']:
                print("This transfer cant be cancelled once is done, make sure you send it to the right person.")
                #calls upon the search for the reciving account
                recieving_acct_username = input("Please enter the username of the person recieving money: ")
                #another try except to handle the exception of not finding the recieving account
                try:
                    with open(os.path.join("C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts", "%s.json" % recieving_acct_username), 'r+') as recipient_account:
                        reciever_balance = json.load(recipient_account)
                        #enter the transfer amounts and checks that sender has the available funds for it
                        transfer_amount = float(input("Please enter the amount of money to be transfered: "))
                        if transfer_amount <= sender_info['Balance ']:
                            #records the transfer on senders json file and txt file
                            sender_updated_balance = sender_info['Balance '] - transfer_amount
                            #print("${:,.2f}.".format(sender_updated_balance))
                            #updates the senders json file
                            sender_info['Balance '] = sender_updated_balance
                            sender_account.seek(0)
                            sender_account.write(json.dumps(sender_info))
                            sender_account.truncate()

                            #updates the transaction history for the sender
                            transaction_update = open(os.path.join("C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances", "%s.txt" % acct_name), 'a+')
                            transaction_update.write("\n" + transfer_time + " - Transfer to " + recieving_acct_username + " ${:,.2f}.".format(transfer_amount))
                            transaction_update.close()

                            #records the transfer on the recipient json file and txt file
                            new_recipient_balance = transfer_amount + reciever_balance['Balance ']
                            #updates recipient json file
                            reciever_balance['Balance '] = new_recipient_balance
                            recipient_account.seek(0)
                            recipient_account.write(json.dumps(reciever_balance))
                            recipient_account.truncate()

                            #save to the text file
                            transaction_update =  open(os.path.join("C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances", "%s.txt" % recieving_acct_username), 'a+')
                            transaction_update.write("\n" + transfer_time + " - Transfer from " + acct_name + " ${:,.2f}.".format(transfer_amount))
                            transaction_update.close()

                        else:
                            print("Insufficient Funds")
                            logging.warning("Not enough funds avaialble  for "  + acct_name)
                            usermenu.main()

                except FileNotFoundError:
                    print("Username not found, transfer cancelled")
                    logging.warning("Transfer cancelled due to not finding the account")
                    usermenu.main()

            else:
                print("Account Number does not match the one on record")
                logging.warning("Invalid account number")
                usermenu.main()

    except FileNotFoundError:
        print("Username not found, returning to main menu")
        logging.error("Account not found")
        usermenu.main()
def main():
    #define basic variables to be used
    now = datetime.now()
    initial_balance_time = now.strftime("%m/%d/%Y")
    print("Withdraw Money from account")
    #define account name to be manipulated
    acct_name = input("Please reenter the account username: "******"C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                    "%s.json" % acct_name), 'r') as acct_balance:
            balance_info = json.load(acct_balance)
            #Verify the account number before proceeding
            account_number = input(
                "Please verify your identity by entering the account number: ")
            if account_number in balance_info['Account Number ']:
                print("Current balance as of " + initial_balance_time +
                      " is " + "${:,.2f}.".format(balance_info['Balance ']))
                #asks for user input for the amount of money to be withdrawn. IF amount enter exceeds amount in balance, traansaction will be declined
                withdrawn_amount = (float(
                    input("Please enter the amount to be withdrawn: ")))
                if withdrawn_amount <= balance_info['Balance ']:
                    #substract the amount entered from the balance
                    new_balance = balance_info['Balance '] - withdrawn_amount
                    #update json with new balance:
                    with open(
                            os.path.join(
                                "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                                "%s.json" % acct_name),
                            'r+') as balance_withdrawn:
                        balance_update = json.load(balance_withdrawn)
                        balance_update['Balance '] = new_balance
                        balance_withdrawn.seek(0)
                        balance_withdrawn.write(json.dumps(balance_update))
                        balance_withdrawn.truncate()

                    #record the transaction on the text file:
                    history_update = open(
                        os.path.join(
                            "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances",
                            "%s.txt" % acct_name), 'a+')
                    history_update.write("\n" + initial_balance_time +
                                         "- Withdrawal - " +
                                         "${:,.2f}.".format(withdrawn_amount))
                    history_update.close()
                    logging.info((acct_name + " has withdrawn the amount of " +
                                  "${:,.2f}.".format(withdrawn_amount)))
                    #return the user to the main menu

                else:
                    print(
                        "Overdraft Protection: The transaction you wish to make is unauthorized due to your withdrawal exceeding your available funds"
                    )
                    logging.error(
                        ("Amount requested can not be higher than " +
                         "${:,.2f}.".format(balance_info['Balance '])))
                    usermenu.main()
            else:
                print(
                    "The account number does not match, returning to main menu"
                )
                logging.error("The account number does not match")
                usermenu.main()
    except FileNotFoundError:
        print("Account does not exist, returning to the main menu")
        logging.error("Info entered does not match our records")
        usermenu.main()
def main():
    now = datetime.now()
    initial_balance_time = now.strftime("%m/%d/%Y")
    print("Deposit Money to account")
    acct_name = input("Please enter the account username: "******"C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                    "%s.json" % acct_name), 'r') as acct_balance:
            balance_info = json.load(acct_balance)
            account_number = input(
                "Please verify your identity by entering the account number: ")
            if account_number in balance_info['Account Number ']:
                print("Current balance as of " + initial_balance_time +
                      " is " + '${:,.2f}'.format(balance_info['Balance ']))
                deposit_amount = (float(
                    input("Please enter the deposit amount: ")))
                if deposit_amount > 0.0:
                    # creating the new balance
                    new_balance = deposit_amount + balance_info['Balance ']

                    # saving to json and
                    with open(
                            os.path.join(
                                "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Accounts",
                                "%s.json" % acct_name),
                            'r+') as balance_update:
                        balance_json = json.load(balance_update)
                        balance_json['Balance '] = new_balance
                        balance_update.seek(0)
                        balance_update.write(json.dumps(balance_json))
                        balance_update.truncate()

                    # Sve to the  transaction history goes here
                    balance_update = open(
                        os.path.join(
                            "C:\\Users\\tito_\\PycharmProjects\\project-0-fcanetti94\\src\\test\\resources\\Balances",
                            "%s.txt" % acct_name), 'a+')
                    balance_update.write("\n" + initial_balance_time +
                                         "- Deposit - " +
                                         "${:,.2f}.".format(deposit_amount))
                    balance_update.close()
                else:
                    print(
                        "Invalid Amount, please enter an amount higher than 0.Returning to menu"
                    )
                    logging.error("Deposit Amount is 0")
                    usermenu.main()

                # after transaction is done return to the user menu
                usermenu.main()
            else:
                print(
                    "Account Number does not match the one on record, please try again."
                )
                logging.warning("INVALID Account number entered")
                usermenu.main()
    except FileNotFoundError:
        print("Username not found, returning to main menu")
        logging.error("Account not found")
        usermenu.main()

    if __name__ == '__main__':
        main()