Ejemplo n.º 1
0
def contact():
    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
        return render_template("contact.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), UserCash=cash)
    else:
        return render_template("contact.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
Ejemplo n.º 2
0
def home(name=WEB_APP_NAME, lb_data=getDashboardData()):
    if not session.get('logged_in'):
        return render_template('login.html', ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
    else:
        with sqlite3.connect('mainDB.db') as conn:
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
            netvalue = DBTools.getNetWorth(conn=conn, userID=str(session['UserName']).lower())
            netvalue = '${:20,.2f}'.format(netvalue)
        return render_template("dashboard.html", data=lb_data, ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), UserCash=cash, NetValue=netvalue)
Ejemplo n.º 3
0
def leaderboard():
    with sqlite3.connect('mainDB.db') as conn:
        data = DBTools.getUserRanks(conn)
        length = len(data) + 1
        data = json.dumps(data)
    if session.get('logged_in'):
        cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
        cash = '${:20,.2f}'.format(cash)
        return render_template("leaderboard.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length, UserCash=cash)
    else:
        return render_template("leaderboard.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length)
Ejemplo n.º 4
0
def portfolio():
    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            userID = session['UserName']
            userID = str(userID).lower()
            data = DBTools.getOwnedStocksByID(conn, userID)
            length = len(data) + 1
            data = json.dumps(data)
            cash = DBTools.getUserCash(conn, userID=str(userID))
            cash = '${:20,.2f}'.format(cash)
            data2 = DBTools.getOwnedStocksByIDPrices(conn, userID=userID)
            length2 = len(data2) + 1
            data2 = json.dumps(data2)
            portfolioValue = DBTools.getPortfolioValue(conn, DBTools.getAllPortData(conn, userID=userID)[0]['portfolioID'])
            portfolioValue = '${:20,.2f}'.format(portfolioValue)

        return render_template("portfolio.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length, UserCash=cash, length2=length2, prices=data2, portValue=portfolioValue)
    else:
        return render_template("login.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
Ejemplo n.º 5
0
def stock_profile(ticker):

    tickerpath = ticker + ".html"
    grabStockGraph(ticker)
    # Action = request.form['Action']
    # Quantity = request.form['Quantity']
    data = StockPrices.getAllStockData(ticker)
    # print(data)

    sUrl = url_for('static', filename='./stockplots/' + tickerpath)


    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            Quant = DBTools.getPortfolioStocks(conn, str(session['UserName']).lower(), ticker)
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
        return render_template("stock.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks(), ticker=ticker, sUrl=sUrl, stock_data=data, ownedQuantity=Quant, UserCash=cash)
    else:
        return render_template("login.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks())
Ejemplo n.º 6
0
def PostStock():
    with sqlite3.connect('mainDB.db') as conn:
        Action = request.form['Action']
        Quantity = request.form['Quantity']
        Ticker = request.form['Ticker']

        TickerPath = Ticker + ".html"
        data = StockPrices.getAllStockData(Ticker)
        sUrl = url_for('static', filename='./stockplots/' + TickerPath)
        User = session['UserName']

        # file = open('testfile.txt','w')
        # file.write(str(User))
        # file.close()
        User2 = str(User)
        Price = StockPrices.getPrice(Ticker)
        Price = float(Price)
        Quantity = float(Quantity)
        total = (Price * Quantity)
        total = '${:20,.2f}'.format(total)
        port = DBTools.getAllPortData(conn, User2)[0]['portfolioID']

        if(Action == 'Buy'):
            if(Trades.buyStock(conn, Ticker, port, Price, Quantity)):
                flash("Purchased " + str(Quantity) + " Stock from " + str(Ticker) + " for " + str(total))
            else:
                flash("Could not Complete Purchase")
        elif(Action == 'Sell'):
            if(Trades.sellStock(conn, Ticker, port, Price, Quantity)):
                flash("Sold " + str(Quantity) + " Stock from " + str(Ticker) + " for " + str(total))
            else:
                flash("Could not Sell Stock")
        Quant = DBTools.getPortfolioStocks(conn, str(session['UserName']).lower(), Ticker)
        cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
        cash = '${:20,.2f}'.format(cash)
        return render_template("stock.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks(), ticker=Ticker, sUrl=sUrl, stock_data=data, ownedQuantity=Quant, UserCash=cash)