Ejemplo n.º 1
0
def menu(account_number):
    while True:
        first_name = model.get_f_name(account_number)
        last_name = model.get_l_name(account_number)
        view.main_menu(account_number, first_name, last_name)
        selection = view.choice()

        if selection == "1":
            model.get_balance(account_number)

        elif selection == "2":
            witdraw = float(view.withdraw())
            model.withdraw_money(account_number, witdraw)
            money_left = model.balance(account_number)

            model.save()
            if money_left < 0:
                view.insuf()

        elif selection == "3":
            depo = float(view.deposit())
            model.add_amount(account_number, depo)
            model.save()
        elif selection == "4":
            model.save()
            return
Ejemplo n.º 2
0
def game_loop(username):
    # Main menu (balance, buy, sell, lookup, quote, portfolio, exit)
    main_done = False
    while not main_done:
        balance_inputs = ["a", "balance"]
        buy_inputs = ["b", "buy"]
        sell_inputs = ["s", "sell"]
        lookup_inputs = ["l", "lookup"]
        quote_inputs = ["q", "quote"]
        portfolio_inputs = ["p", "portfolio"]
        exit_inputs = ["e", "exit"]

        acceptable_inputs = balance_inputs\
           +buy_inputs\
           +sell_inputs\
           +lookup_inputs\
           +quote_inputs\
           +portfolio_inputs\
           +exit_inputs

        user_input = view.main_menu(username)
        # If the user input is acceptable.
        if user_input.lower() in acceptable_inputs:
            # Balance
            if user_input.lower() in balance_inputs:
                balance = model.get_balance(username)
                view.balance_menu(balance)
            # Buy
            elif user_input.lower() in buy_inputs:
                ticker_symbol, trade_volume = view.buy_menu()
                res = model.buy(ticker_symbol, trade_volume, username)
                view.display_response(res)
            # Sell
            elif user_input.lower() in sell_inputs:
                ticker_symbol, trade_volume = view.sell_menu()
                res = model.sell(ticker_symbol, trade_volume, username)
                view.display_response(res)
            # Lookup
            elif user_input.lower() in lookup_inputs:
                company_name = view.lookup_menu()
                ticker_symbol = model.get_ticker_symbol(company_name)
                view.display_ticker_symbol(ticker_symbol)
            # Quote
            elif user_input.lower() in quote_inputs:
                ticker_symbol = view.quote_menu()
                last_price = model.get_last_price(ticker_symbol)
                view.display_last_price(last_price)
            # Portfolio (Holdings)
            elif user_input.lower() in portfolio_inputs:
                df = model.get_holdings_dataframe(username)
                balance = model.get_balance(username)
                earnings = model.get_earnings(username)
                view.display_dataframe(df, balance, earnings, username)
            # Exit
            elif user_input.lower() in exit_inputs:
                view.exit_message()
                main_done = True
            # Otherwise
            else:
                return "Error"
Ejemplo n.º 3
0
def buy_stock(symbol, qty, username):
    user_id = model.get_user_id(username)
    last_price = get_quote(symbol)
    if last_price == False:
        response = 500
        return (0, 0, 0, response)
    else:
        total_price = qty * last_price
    if model.get_balance(user_id) < total_price:
        response = 400
        return (0, 0, 0, response)
    else:
        response = 200
        model.buy_stock(user_id, symbol, last_price, total_price, qty)
        return last_price, total_price, model.get_balance(user_id), response
def main_menu(user):
    while True:
        view.print_main_menu(user)
        choice = view.main_prompt()
        """ TODO: add bad input message """
        if choice not in ("1", "2", "3", "4"):
            view.bad_login_input()
            return main_menu(user)
        if choice == "4":
            # user["balance"] += 1.0 # delete this, just demonstrating model.save()
            # model.save(user)
            return login_menu()
        if choice == "3":
            amount = round(float(view.enter_deposit_info()), 2)
            model.deposit(user, amount)
            return main_menu(user)
        if choice == "2":
            amount = round(float(view.enter_withdraw_info()), 2)
            answer = model.withdraw(user, amount)
            if answer == 0:
                view.insufficient_funds()
            return main_menu(user)
        if choice == "1":
            balance = round(model.get_balance(user), 2)
            view.give_balance(balance)
        """ TODO: implement the various options """
Ejemplo n.º 5
0
def get_balance(apikey):
    user_name = model.api_authenticate(apikey)
    if not user_name:
        return (jsonify({"error": "count not authenticate"}))
    return jsonify({
        "username": user_name,
        "balance": model.get_balance(user_name)
    })
Ejemplo n.º 6
0
def customer_menu():
    while True:
        choice = viewer.existing_customer_menu()
        #Deposit
        if choice == "1":
            #Authentication
            name = viewer.get_name()
            pin = viewer.get_pin()
            auth_validation = model.authentication(name, pin)
            if auth_validation == True:
                deposit = viewer.get_deposit_input()
                model.deposit(name, deposit)
            else:
                viewer.wrong_pin()

        #Get Balance
        elif choice == "2":
            #Authentication
            name = viewer.get_name()
            pin = viewer.get_pin()
            print(name, pin)
            auth_validation = model.authentication(name, pin)
            print(auth_validation)
            if auth_validation == True:
                balance = model.get_balance(name)
                viewer.show_balance(balance)
            else:
                viewer.wrong_pin()
        #Withdraw
        elif choice == "3":
            #Authentication
            name = viewer.get_name()
            pin = viewer.get_pin()
            auth_validation = model.authentication(name, pin)
            if auth_validation == True:
                #Withdraw
                withdraw_amount = viewer.get_withdraw_input()
                model.withdraw(name, withdraw_amount)
            else:
                viewer.wrong_pin()
        #Update Pin
        elif choice == "4":
            #Authentication
            name = viewer.get_name()
            pin = viewer.get_pin()
            auth_validation = model.authentication(name, pin)
            if auth_validation == True:
                #Update Pin
                new_pin = viewer.change_pin()
                model.update_pin(name, new_pin)
            else:
                viewer.wrong_pin()

        elif choice == "5":
            viewer.goodbye()
        else:
            viewer.bad_input()
Ejemplo n.º 7
0
def user_menu(user_account):
    while True:
        view.show_user_menu()
        selection = view.get_input()
        if selection == "4":
            return
        elif selection == "1":
            view.show_balance(model.get_balance(user_account))
        elif selection == "2":
            print("wit")
            withdraw_amount = int(view.subtract_funds())
            current_balance = int(model.get_balance(user_account))
            if withdraw_amount > current_balance:
                print("insufficient funds")
            else:
                model.withdraw_funds(user_account, withdraw_amount)

        elif selection == "3":
            add_amount = view.add_funds()
            model.add_funds(user_account, add_amount)
        else:
            view.bad_input()
Ejemplo n.º 8
0
def get_deposit(apikey):
    if not request.json or not 'Deposit' in request.json:
        abort(400)
    if not isinstance(request.json['Deposit'], (float, int)):
        abort(400)
    user_name = model.api_authenticate(apikey)
    if not user_name:
        return (jsonify({"error": "count not authenticate"}))
    money = request.json['Deposit']
    model.deposit(user_name, money)
    return jsonify({
        "username": user_name,
        "Deposit": money,
        "Balance": model.get_balance(user_name)
    })
Ejemplo n.º 9
0
def mainmenu(clientname, accountcheck):
    while True:
        view.show_mainmenu(clientname, accountcheck)
        selection = view.get_input()
        print(selection)
        if selection == '1':
            view.show_balance(model.get_balance(clientname))
        elif selection == '3':
            model.add_fund(clientname, view.get_deposit())

        elif selection == '2':
            model.withdraw(clientname, view.get_withdraw())
            pass
        elif selection == '4':
            view.goodby()
            initialmenu()
        else:
            view.bad_input()
Ejemplo n.º 10
0
def sell_stock(symbol, qty, username):
    user_id = model.get_user_id(username)
    last_price = get_quote(symbol)
    if last_price == False:
        response = 500
        return (0, 0, 0, response)
    else:
        total_price = qty * last_price
    if model.get_stock_qty(user_id, symbol) == None:
        response = 401
        return (0, 0, 0, response)
    elif model.get_stock_qty(user_id, symbol) < qty:
        response = 400
        return (0, 0, 0, response)
    else:
        response = 200
        model.sell_stock(user_id, symbol, last_price, total_price, qty)
        return last_price, total_price, model.get_balance(user_id), response
Ejemplo n.º 11
0
         view.pause()
     elif selection.strip() == '2' or selection.strip(
     ) == 'CREATE ACCOUNT' or selection.strip() == 'create account':
         username, password, balance = view.create_account()
         pk = model.save_create_account(username, password, balance)
         exit_terminal == True
 while pk == None:
     username, password = view.login_prompt(True)
     pk = model.login(username, password)
 exit_terminal = False
 while exit_terminal == False:
     option = view.main_menu()
     if option.strip() == "0":
         exit_terminal = True
     elif option.strip() == "1":
         balance = model.get_balance(pk)
         holdings = model.get_holdings(pk)
         view.show_status(balance, holdings)
         view.pause()
     elif option.strip() == '3':
         ticker_symbol, number_of_shares = view.sell_menu()
         status = model.sell(pk, ticker_symbol, number_of_shares)
         if status == False:
             view.sell_error()
             view.pause()
         else:
             view.sell_good()
             view.pause()
     elif option.strip() == '5':
         ticker_symbol = view.quote_prompt()
         quote = model.quote(ticker_symbol)
Ejemplo n.º 12
0
def admin_loop(username):
    # Admin menu (balance, deposit, withdraw, set, portfolio, leaderboard, users, exit)
    admin_done = False
    while not admin_done:
        balance_inputs = ["a", "balance"]
        deposit_inputs = ["d", "deposit"]
        withdraw_inputs = ["w", "withdraw"]
        set_inputs = ["t", "set"]
        portfolio_inputs = ["p", "portfolio"]
        leaderboard_inputs = ["l", "leaderboard"]
        users_inputs = ["u", "users"]
        exit_inputs = ["e", "exit"]

        acceptable_inputs = balance_inputs\
           +deposit_inputs\
           +withdraw_inputs\
           +set_inputs\
           +portfolio_inputs\
           +leaderboard_inputs\
           +users_inputs\
           +exit_inputs

        user_input = view.admin_menu()
        # If the user input is acceptable.
        if user_input.lower() in acceptable_inputs:
            # Balance
            if user_input.lower() in balance_inputs:
                username = view.admin_balance_menu()
                balance = model.get_balance(username)
                view.admin_display_balance(username, balance)
            # Deposit
            elif user_input.lower() in deposit_inputs:
                username, balance_to_add = view.admin_deposit_menu()
                balance = model.get_balance(username)
                new_balance = model.calculate_new_deposit(
                    balance, balance_to_add)
                model.update_balance(new_balance, username)
                view.admin_display_new_balance(username, balance, new_balance)
            # Withdraw
            elif user_input.lower() in withdraw_inputs:
                username, balance_to_subtract = view.admin_withdraw_menu()
                balance = model.get_balance(username)
                new_balance = model.calculate_new_withdraw(
                    balance, balance_to_subtract)
                model.update_balance(new_balance, username)
                view.admin_display_new_balance(username, balance, new_balance)
            # Set
            elif user_input.lower() in set_inputs:
                username, balance_to_set = view.admin_set_menu()
                balance = model.get_balance(username)
                new_balance = model.calculate_new_set(balance, balance_to_set)
                model.update_balance(new_balance, username)
                view.admin_display_new_balance(username, balance, new_balance)
            # Portfolio
            elif user_input.lower() in portfolio_inputs:
                username = view.admin_portfolio_menu()
                df = model.get_holdings_dataframe(username)
                balance = model.get_balance(username)
                earnings = model.get_earnings(username)
                view.display_dataframe(df, balance, earnings, username)
            # Leaderboard
            elif user_input.lower() in leaderboard_inputs:
                view.admin_leaderboard_wait()
                leaderboard = model.get_leaderboard()
                view.admin_display_leaderboard(leaderboard)
            # Users
            elif user_input.lower() in users_inputs:
                users = model.get_users()
                view.admin_display_users(users)
            # Exit
            elif user_input.lower() in exit_inputs:
                view.exit_message()
                admin_done = True
            # Otherwise
            else:
                return "Error"
Ejemplo n.º 13
0
 def balance():
     email = session.get("user")
     result = get_balance(email)
     return result