Пример #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
Пример #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"
Пример #3
0
def game_loop():
	while True:
		#x = input('what do you want to do?')
		buy_inputs = ['b', 'buy']
		sell_inputs = ['s', 'sell']
		lookup_inputs = ['l', 'lookup']
		quote_inputs = ['q', 'quote']
		exit_inputs = ['e', 'exit']
		acceptable_inputs = buy_inputs \
				    + sell_inputs \
				    + lookup_inputs \
				    + quote_inputs \
				    + exit_inputs
		user_input = view.main_menu()
		if user_input.lower() in acceptable_inputs:
			if user_input.lower() in buy_inputs:
				pass
			elif user_input.lower() in sell_inputs:
				pass
			elif user_input.lower() in lookup_inputs:
				company_name = view.lookup_menu()
				ticker_symbol = model.get_ticker_symbol(company_name)
				return ticker_symbol
			elif user_input.lower() in  quote_inputs:
				ticker_symbol = view.quote_menu()
				last_price = model.get_last_price(ticker_symbol)
				return last_price
			elif user_input.lower() in exit_inputs:
				#TODO add exit message in the view module
				break
			else:
				return 'Error'
Пример #4
0
def game_loop():
    user_input = view.main_menu()
    buy_inputs = ['b', 'buy']
    sell_inputs = ['s', 'sell']
    lookup_inputs = ['l', 'lookup']
    quote_inputs = ['q', 'quote']
    exit_inputs = ['e', 'exit']
    view_inputs = ['v', 'view']
    pl_inputs = ['p', 'p']
    acceptable_inputs = buy_inputs      \
        + sell_inputs   \
        + lookup_inputs \
        + quote_inputs  \
        + exit_inputs   \
        + view_inputs   \
        + pl_inputs
    on_off_switch = True
    while on_off_switch:
        if user_input.lower() in acceptable_inputs:
            if user_input.lower() in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                x = model.buy(ticker_symbol, trade_volume)
                return x

            elif user_input.lower() in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                x = model.sell(ticker_symbol, trade_volume)
                return x

            elif user_input.lower() in lookup_inputs:
                company_name = view.lookup_menu()
                x = model.lookup(company_name)
                return x

            elif user_input.lower() in quote_inputs:
                ticker_symbol = view.quote_menu()
                x = model.quote(ticker_symbol)
                return x

            elif user_input.lower() in view_inputs:
                balance = view.portfolio_menu()
                x = model.portfolio(balance)
                return x

            elif user_input.lower() in pl_inputs:
                p = view.pl_menu()
                x = model.pl(p)
                return x

            elif user_input.lower() in exit_inputs:
                break
                #on_off_switch = False
            else:
                print('Bad input. Restarting game in five seconds...')
                time.sleep(5)
                game_loop()
        else:
            return 'Plese Start Over'
def run():
    play = True
    while play == True:
        rows, columns = view.main_menu()
        #return error for non-numeric input
        if rows.isnumeric() == False or columns.isnumeric() == False:
            view.not_num()
        play = False

    rows = int(rows)
    columns = int(columns)
    battleship = model.Gameboard(rows, columns)
    view.show_board(battleship.board, rows)
    print(battleship.ship_row, battleship.ship_column)
    print(type(battleship.board))

    play = True
    while play == True:
        #TODO Error handling when input is out of range or not number
        view.input_coordinates()
        #return error for non-numeric input or not in range input
        guess_again = True
        while guess_again == True:
            guess_column = view.guess_x()
            if guess_column.isnumeric() == False:
                view.not_num()
            elif int(guess_column) > columns or int(guess_column) < 1:
                view.input_not_in_range(columns)
            else:
                guess_again = False

        guess_again = True
        while guess_again == True:
            guess_row = view.guess_y()
            if guess_row.isnumeric() == False:
                view.not_num()
            elif int(guess_row) > rows or int(guess_row) < 1:
                view.input_not_in_range(rows)
            else:
                guess_again = False

        guess_row = int(guess_row) - 1
        guess_column = int(guess_column) - 1
        view.fire()

        #Compare guess to battleship location
        #win condition
        if guess_row == battleship.ship_row and guess_column == battleship.ship_column:
            battleship.board[guess_row][guess_column] = "S"
            view.win()
            view.show_board(battleship.board, rows)
            return
        #miss condition
        battleship.board[guess_row][guess_column] = "X"
        view.miss()
        view.show_board(battleship.board, rows)
Пример #6
0
def run():
    while True:
        choice = view.main_menu()
        if choice == "3":  #Exit
            return
        elif choice == "1":  #Create Account
            view.create_account()
            fname = view.first_name()
            lname = view.last_name()
            pin = view.choose_pin()
            initial = float(view.deposit_initial())
            #Create new account then display
            view.new_account(model.create_account(fname, lname, pin, initial))

        elif choice == "2":  #log in
            account_num, pin = view.login()
            #Check if login info is correct
            if model.login(account_num, pin) == False:
                view.bad_login()
            else:
                #Login Menu - Check Balance, Withdraw, Deposit, Open Savings Account
                info = model.login(account_num, pin)
                view.welcome(account_num, info)
                while True:
                    choice = view.login_menu()
                    if choice == "1":
                        view.check_balance(info)
                    elif choice == "2":
                        login_withdrawal(account_num)  #see line 58
                    elif choice == "3":
                        num = view.deposit()
                        new_balance = model.deposit(num, account_num)
                        view.deposit_new_balance(num, new_balance)
                    elif choice == "4":
                        from_account, to_account, amount = view.transfer()

                        #Add " account" at the end of the string so it matches the key in the dictionary
                        from_account = from_account + " account"
                        to_account = to_account + " account"
                        #convert amount value from string to float
                        amount = float(amount)

                        info = model.transfer(from_account, to_account, amount,
                                              account_num)
                        view.transfer_new_balance(info, from_account,
                                                  to_account)
                    elif choice == "5":
                        yesorno, deposit = view.create_savings()
                        model.open_savings(yesorno, float(deposit),
                                           account_num)
                        view.savings_opened(float(deposit))
                    elif choice == "6":
                        view.signout()
                        return
        else:
            view.bad_input()
Пример #7
0
def main_loop():
    user_input = view.main_menu()
    account_input = '1'
    login_input = '2'
    quit = '3'
    if user_input == account_input:
        account_create_loop()
    if user_input == login_input:
        login_loop()
    if user_input == quit:
        print("Goodbye.")
        exit()
Пример #8
0
def game_loop():
    while True:
        user_input = view.main_menu().lower()
        buy_inputs = ["b", "buy"]
        sell_inputs = ["s", "sell"]
        lookup_inputs = ["l", "lookup"]
        quote_inputs = ["q", "quote"]
        exit_inputs = ["e", "exit"]

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

        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                # FIXME
                # State of the Program:
                ## User wants to buy stock
                ### company referred to by TICKER SYMBOL
                #### global unique identifiers

                ## What we should try to do next (ie sudo code)
                ##   --trader_name
                ##   --ticker_symbol
                ##   --trade_volume
                ##   --limit_price --> coming from `view`
                ##   --time_stamp --> defined in `model`
                ## "we're building out the order ticket"

                (username, password) = view.login_menu()
                (ticker_symbol, trade_volume) = view.buy_menu()
                #######################################

                with model.User(username) as u:
                    if u.login(password):
                        # excute the buy order,
                        # if there's enough money in acct
                        confirmation_message = u.buy(ticker_symbol,
                                                     trade_volume)
                        print(confirmation_message)
                    pass

                pass
            elif user_input in sell_inputs:
                # FIXME
                pass
Пример #9
0
def command_func(com):
    global command2
    com = view.main_menu()
    if com == 1:
        base.view_base()
        return 1
    if com == 2:
        command2 = view.sec_menu()
        if command2 == 1:
            base.new_faculty()
        if command2 == 2:
            base.new_group()
        return 1
    if com == 3:
        command2 = view.sec_menu()
        if command2 == 1:
            base.change_faculty()
        if command2 == 2:
            base.change_group()
        return 1
    if com == 4:
        command2 = view.sec_menu()
        if command2 == 1:
            base.del_faculty()
        if command2 == 2:
            base.del_group()
        return 1
    if com == 5:
        base.filter()
        return 1
    if com == 6:
        base.save_base()
        return 1
    if com == 7:
        base.refresh_from_f()
        return 1
    if com == 8:
        base.del_base()
        return 1
    if com == 9:
        return 0

    if com in range(1, 8):
        print("Неверный номер, попробуйте еще.")
Пример #10
0
def game_loop():
    user_input = view.main_menu()
    lookup_inputs = ['l', 'lookup', 'look-up', 'lookup']
    quote_inputs = ['q', 'quote']
    acceptable_inputs = lookup_inputs \
          +quote_inputs
    if user_input in acceptable_inputs:
        if user_input in lookup_inputs:
            x = view.lookup_menu()
            y = model.lookup(x)
            print(y)
        elif user_input in quote_inputs:
            x = view.quote_menu()
            y = model.quote(x)
            print(y)
        else:
            print('Error: uncaught exception')
    else:
        print('Error: uncaught exception')
Пример #11
0
def main_menu(account): 
    while True:

        choice = view.main_menu()
        if choice == "1":
            balance = account.balance
            print(balance)
        elif choice == "2":
            withdraw = view.withdraw()
            account.withdraw(withdraw)
            account.save()
        elif choice == "3":
            depo = view.deposit()
            account.deposit(depo)
            account.save()
        elif choice == "4":
            account.save()
            return
        else:
            view.bad_input()
Пример #12
0
def game_loop():
    while True:
        #x = input('what do you want to do?')
        acceptable_inputs = ['b', 's', 'l', 'q', 'e']
        user_input = view.main_menu()
        if user_input.lower() in acceptable_inputs:
            if user_input == 'b':
                pass
            elif user_input == 's':
                pass
            elif user_input == 'l':
                pass
            elif user_input == 'q':
                ticker_symbol = view.quote_menu()
                last_price = model.get_last_price(ticker_symbol)
                return last_price
            elif user_input == 'e':
                #TODO add exit message in the view module
                break
            else:
                return 'Error'
Пример #13
0
#location : tiketPesawat
from datetime import datetime

#Module punya sendiri
from models import ticket, user
import view
import system

system.tickets = system.load_ticket_data()
system.users = system.load_user_data()

while not system.error :
	view.main_menu()

Пример #14
0
import view
import model
import time

while True:
    menu_item = view.main_menu()
    print(menu_item)
    if menu_item == '1':
        attrs = view.insert_menu()
        try:
            getattr(model, f'insert_{attrs[0]}')(attrs[1].split(','))
        except:
            print("Oops, table doesn't exists")

    elif menu_item == '2':
        attrs = view.delete_menu()
        model.delete(*attrs)
    elif menu_item == '3':
        attrs = view.update_menu()
        model.update(*attrs)
    elif menu_item == '4':
        attrs = view.random_menu()
        try:
            view.show_random_query(
                getattr(model, f'random_{attrs[0]}')(int(attrs[1])))
        except:
            print("Oops, table doesn't exists")
    elif menu_item == '5':
        attrs = view.select_menu()
        f_name = [
            'student_grade', 'teacher_subject', 'student_teacher_subject'
Пример #15
0
     ) == 'LOG IN' or selection.strip() == 'log in':
         username, password = view.login_prompt()
         pk = model.login(username, password)
         exit_terminal = True
         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()
Пример #16
0
def game_loop():
    current_username = ''
    condition = True
    while 1:
        user_choice = view.log_or_sign()
        user_choice = user_choice.lower()
        log_in = ['l', 'login']
        create_ = ['c', 'create']
        exit_ = ['e', 'exit']
        accept_input = log_in     \
                      +create_     \
                      +exit_
        if user_choice in accept_input:
            if user_choice in log_in:
                (user_name, password) = view.log_menu()
                current_username = user_name
                has_account = model.log_in(user_name, password)
                if has_account:
                    break
                else:
                    print('WRONG LOGIN INFORMATION. TRY AGAIN')
                    import time
                    time.sleep(3)
            elif user_choice in exit_:
                condition = False
                m.log_out()
                os.system('clear')
                break

            elif user_choice in create_:
                #(new_user,new_password,new_funds) = view.create_menu()
                #       new_user = input("username:"******"password:"******"""INSERT INTO user(
                        username,
                        password,
                        current_balance
                    ) VALUES(?,?,?
                    )""", newuser)
                connection.commit()
                cursor.close()
                connection.close()

                print("You have signed up!")
                import time
                time.sleep(3)

    while condition:
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup']
        quote_inputs = ['q', 'quote']
        exit_inputs = ['e', 'exit']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +exit_inputs
        user_input = view.main_menu()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                confirmation_message, return_list = model.buy(
                    current_username, ticker_symbol, trade_volume)
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input(
                        "You have enough money. Would you like to buy this stock?\n[y] Yes\n[n] No\n"
                    )
                    if choice in yes:
                        model.buy_db(return_list)
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough money to buy this stock.")
            elif user_input in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                confirmation_message, return_list = model.sell(
                    current_username, ticker_symbol, trade_volume)  #TODO
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input(
                        "You have enough shares to sell. Would you like to sell this stock?\n[y] Yes\n[n] No\n"
                    )
                    if choice.lower() in yes:
                        model.sell_db(return_list)  #TODO
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough shares to sell.")

            elif user_input in lookup_inputs:
                company_name = view.lookup_menu()
                print(model.lookup_ticker_symbol(company_name))
            elif user_input in quote_inputs:
                #TODO
                ticker_symbol = view.quote_menu()
                print(model.quote_last_price(ticker_symbol))
                #import time
                #time.sleep(5)
            elif user_input in exit_inputs:
                os.system('clear')
                break
            else:
                #catches huge error
                #should contain a fallback function
                pass
        else:
            pass
        model.updateHoldings()
        import time
        time.sleep(3)
Пример #17
0
        os.system('scp {0}/.ssh/id_rsa.pub root@{1}:/etc/ssh/{2}/authorized_keys'.format(expanduser('~'), ip_address, username))

        os.system('sh -c \'echo "{0}" > .htpasswd-credentials\''.format(password))
        os.system('sh -c \'echo "{1}:{0}" > .chpasswd-credentials\''.format(password, username))
        os.system('scp .htpasswd-credentials root@{0}:/home/{1}/'.format(ip_address, username))
        os.system('scp .chpasswd-credentials root@{0}:/home/{1}/'.format(ip_address, username))
        os.system('rm .htpasswd-credentials')
        os.system('rm .chpasswd-credentials')

        os.system('scp root@{0}:/etc/pki/tls/certs/logstash-forwarder.crt .'.format(ip_address)) # TODO Find a place to store the certificate

        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/docker/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/elastic_search/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/fail2ban/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/firewalld/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/kibana/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/logstash/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/nano/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/nginx/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/openssh/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))
        os.system('ssh -o "StrictHostKeyChecking no" root@{2} \'bash -s\' < procedures/systemd/configuration-{1}-{0}.sh'.format(count, hostname, ip_address))

        count += 1

    return ip_addresses


if __name__ == '__main__':
    (hostname, ssh_port, email, username, password, k) = view.main_menu()
    print(provision(hostname, ssh_port, email, username, password, k))
Пример #18
0
def main():
    create_db.create_tables()
    view.main_menu()
Пример #19
0
def run():
    model.load()
    view.main_menu()
    selection = view.get_input()
    mainmenu(selection)
Пример #20
0
def game_loop():
    current_username = ''
    condition = True
    while 1:
        user_choice = view.log_or_sign()
        user_choice = user_choice.lower()
        log_in = ['l','login']
        create_ = ['c','create']
        exit_ = ['e','exit']
        accept_input = log_in    \
                    +create_     \
                    +exit_
        if user_choice in accept_input:
            if user_choice in log_in:
                (user_name, password) = view.log_menu()
                current_username = user_name
                has_account = model.log_in(user_name, password)
                if has_account:
                    break
                else:
                    input("You have entered the wrong login information. \nPlease try again. Press enter to continue. ")
            elif user_choice in exit_:
                condition = False
                m.log_out()
                view.clear_screen()
                break
            elif user_choice in create_:
                model.create_()
                print("You have signed up!")
                input("Press enter to continue. ")
    while condition: #while true, the loop continues
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup']
        quote_inputs = ['q', 'quote']
        funds = ['f', 'funds']
        holdings = ['h', 'holdings']
        transactions = ['t', 'transactions']
        exit_inputs = ['e', 'exit']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +funds         \
                            +holdings      \
                            +transactions  \
                            +exit_inputs
        user_input = view.main_menu()
        user_input = user_input.lower()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                confirmation_message, return_list = model.buy(current_username, ticker_symbol, trade_volume)
                if confirmation_message == True: #if the transaction cost is less than the current balance
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input("You have enough money. Would you like to buy this stock?\n[y] Yes\n[n] No\n")
                    if choice in yes:
                        model.buy_db(return_list)
                        print("You have bought {} shares of {}. ".format(trade_volume, ticker_symbol))
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough money to buy this stock.")
            elif user_input in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                confirmation_message, return_list = model.sell(current_username, ticker_symbol, trade_volume)
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input("You have enough shares to sell. Would you like to sell this stock?\n[y] Yes\n[n] No\n")
                    if choice.lower() in yes:
                        model.sell_db(return_list)
                        print("You have sold {} shares of {}. ".format(trade_volume, ticker_symbol))
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough shares to sell.")
            elif user_input in lookup_inputs:
                company_name = view.lookup_menu()
                ticker_symbol = model.lookup_ticker_symbol(company_name)
                if len(ticker_symbol) <=6: #if it returns an actual ticker symbol instead of the error message
                    print("The ticker symbol for {} is {}.".format(company_name, ticker_symbol))
                else: #error message
                    print("The ticker symbol for the company you searched cannot be found. \nPlease try again.")
            elif user_input in quote_inputs:
                ticker_symbol = view.quote_menu()
                last_price = model.quote_last_price(ticker_symbol)
                if len(str(last_price)) <= 6:
                    print("The last price for {} is ${}.".format(ticker_symbol, last_price))
                else:
                    print("The last price for the company you searched cannot be found. \nPlease try again.")
            elif user_input in funds:
                view.clear_screen()
                bal = model.funds()
                print("Your current balance is ${}.".format(bal))
            elif user_input in holdings:
                view.clear_screen()
                holdings = m.holdings()
                print("Your current holdings: \n{}".format(holdings))
            elif user_input in transactions:
                view.clear_screen()
                transactions = m.transactions()
                print("All of your previous transactions: \n{}".format(transactions))
            elif user_input in exit_inputs:
                view.clear_screen()
                condition = False
                m.log_out()
                break
            else:
                print("Error.")
        else:
            print("Error.")
        model.update_holdings()
        input("\nPress enter to continue. ")
Пример #21
0
def game_loop():
    start = view.start_up_menu()
    if start == "s":
        (user_name, password) = view.sign_up_menu()
        model.sign_up(user_name, password)
    else:
        (user_name, password) = view.logg_in_menu()
        _id = model.user_check(password)
        print(_id)

    while 1:
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup', 'look up', 'look-up']
        quote_inputs = ['q', 'quote']
        exit_inputs = ['e', 'exit', 'quit']
        view_inputs = ['v']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +exit_inputs   \
                            +view_inputs
        user_input = view.main_menu()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                balance = model.check_balance(user_name)
                fee = 6.25
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.transaction_menu(balance, ticker_symbol,
                                                     price)
                transaction_cost = (float(trade_volume) * price) + fee
                if transaction_cost <= balance:
                    balance -= transaction_cost
                    model.update_cash(user_name, balance)
                    model.buy(user_name, ticker_symbol, float(trade_volume),
                              float(price))
                    model.buy_holdings(user_name, ticker_symbol,
                                       float(trade_volume), price)
                else:
                    print("Not enough monay")

            elif user_input in sell_inputs:
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.sell_menu()
                owned = model.check_holdings(user_name, ticker_symbol)
                if owned and int(trade_volume) <= owned:
                    model.sell_holdings(user_name, ticker_symbol, trade_volume,
                                        price, owned)

            elif user_input in lookup_inputs:
                return model.lookup(view.lookup_menu())
            elif user_input in quote_inputs:
                return model.quote(view.quote_menu())
            elif user_input in view_inputs:
                users = model.get_users()
                users_list = [
                ]  # this is a list of all the users that currenttly have holdings
                for i in users:
                    users_list.append(i[0])

                users_holdings = [
                ]  # users holdings by tickers but not numbers
                for i in users_list:
                    user_holdings = model.get_holdings(i)
                    a = []
                    for i in user_holdings:
                        a.append(i[0])
                    users_holdings.append(a)

                tickers = [
                ]  # is all the stocks the users, un "set'd" and joinined together
                for i in users_holdings:
                    for j in i:
                        tickers.append(j)
                prices = {
                }  # this has all the prices for all the stocks owned in the holdings
                for i in set(tickers):  #
                    price = model.quote(i)
                    prices[i] = price

                volumes = [
                ]  # a list of lists of amount of stock each of them own
                for i in users_list:
                    volumes.append(model.holdings_volumes(i))
                # print(users_holdings)
                # print(volumes)
                values_final = {}
                for i in range(len(users_holdings)):
                    total = 0
                    for j in range(len(users_holdings[i])):
                        total += (prices[users_holdings[i][j]]) * (
                            volumes[i][j][0])
                    values_final[users_list[i]] = total
                highest = 0
                sorted_words = {}
                while values_final:
                    for i in values_final:
                        if values_final[i] >= highest:
                            highest = values_final[i]
                            word = i
                    sorted_words[word] = highest
                    values_final.pop(i)
                    highest = 0
                for i in sorted_words:
                    print("{} : {}".format(i, sorted_words[i]))
                    # highest = 0
                # while values_final:
                #     for i in range(len(values))
                #     if values[i]

                # need to add total balance
                #work vwamp

            elif user_input in exit_inputs:
                break
Пример #22
0
import sqlite3
import os
import time

import model
import view


while True:
    choice = view.main_menu()
    if choice.upper() == 'C':
        view.add_class()
        subject = input('Subject: ')
        room = int(input('Room number: '))
        t_id = int(input('Teacher ID: '))
        capacity = int(input('Class capaciiy: '))
        c_id = int(input('Class ID: '))
        success = model.add_class(subject,room,t_id,capacity,c_id)
        if success:
            view.success('Class')
        else:
            view.error()

    elif choice.upper() == 'T':
        view.add_teacher()
        first = input('First name: ')
        last = input('Last name: ')
        homeroom = int(input('Homeroom number: '))
        subj = input('Subject: ')
        phone = input('Phone number: ')
        tenure = input('Tenure (1/0): ')