Example #1
0
def lookup():
    if request.method == 'GET':
        return render_template('lookup.html')
    else:
        submitted_company_name = request.form['company_name']
        result = model.lookup_ticker_symbol(submitted_company_name)
        return render_template('lookup.html', result=result)
Example #2
0
def search():
    current_user = m.current_user()
    if request.method == "GET":
        if current_user == "randomuser":
            return redirect("/")
        else:
            return render_template("search.html")
    elif request.method == "POST":
        try:
            submitted_company_name = request.form["company_name"]
            submitted_company_name = submitted_company_name.capitalize()
            ticker_symboll = m.lookup_ticker_symbol(submitted_company_name)
            if ticker_symboll:
                result = "The ticker symbol for {} is {}.".format(
                    submitted_company_name, ticker_symboll
                )
                return render_template("search.html", resultthree=result)
            else:
                return render_template("search.html", company_dne=True)

        except Exception:
            submitted_symbol = request.form["ticker_symbol"]
            submitted_symbol = submitted_symbol.upper()
            price = m.quote_last_price(submitted_symbol)
            results = "The last price of {} is ${}.".format(submitted_symbol, price)
            return render_template("search.html", resultfour=results)
def _lookup(apikey):
    if not pk:
        return errormsg("could not authenticate")
    if not request.json:
        return errormsg("Invalid format")
    if "company" not in request.json:
        return errormsg("No company name")
    company = request.json["company"]

    response = m.lookup_ticker_symbol(company_name)
    if not response:
        return jsonify({
            "error": True,
            "company_name": company_name,
            "message": "look up failed"
        })
    else:
        return jsonify({
            "error": False,
            "company_name": company_name,
            "message": "last sale"
        })
Example #4
0
def search():
    current_user = m.current_user()
    if request.method == "GET":
        if current_user == 'randomuser':
            return redirect('/')
        else:
            return render_template('search.html')
    elif request.method == "POST":
        try:
            submitted_company_name = request.form['company_name']
            submitted_company_name = submitted_company_name.capitalize()
            ticker_symboll = m.lookup_ticker_symbol(submitted_company_name)
            result = "The ticker symbol for {} is {}.".format(
                submitted_company_name, ticker_symboll)
            return render_template('search.html', resultthree=result)
        except:
            submitted_symbol = request.form['ticker_symbol']
            submitted_symbol = submitted_symbol.upper()
            price = m.quote_last_price(submitted_symbol)
            results = "The last price of {} is ${}.".format(
                submitted_symbol, price)
            return render_template('search.html', resultfour=results)
        else:
            return render_template('search.html')
Example #5
0
def serve_ticker_symbol(company_name):
    #return str(model.lookup_ticker_symbol(company_name))
    return render_template("lookup.html", \
       company_name=company_name, \
       ticker_symbol=model.lookup_ticker_symbol(company_name))
Example #6
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)
Example #7
0
 def test_lookup_ticker_symbol_fail(self):
     assert not m.lookup_ticker_symbol("asdf")
Example #8
0
 def test_lookup_ticker_symbol_success(self):
     """Make the external API call to test status of API key"""
     assert m.lookup_ticker_symbol("Apple") == "AAPL"
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. ")
Example #10
0
def test_lookup_ticker_symbol_success():
    assert m.lookup_ticker_symbol('Apple') == 'AAPL'