def settings(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) configBool = getConfig(ID) vartable = addZero(getAllVarCost(ID),"var") fixtable = addZero(getAllFixCost(ID),"fix") try: moneyTable = getMoneyTable(ID) allocateTable = getAllocateTable(ID) for each in moneyTable: moneyTable[each] = '{:.2f}'.format(moneyTable[each]) for each in allocateTable: allocateTable[each] = '{:.2f}'.format(allocateTable[each]) except: moneyTable = {'otherIncome': 0, 'currentMoney': 0, 'savings': 0, 'monthIncome': 0, 'savingPercent': 0} allocateTable = {'eatOut': 0, 'entertain': 0, 'shop':0, 'misc':0, 'grocery':0, 'event':0} if vartable == None: vartable = [] if fixtable == None: fixtable = [] return render_template("settings.html", vartable = vartable, fixtable = fixtable, moneyTable = moneyTable, allocateTable = allocateTable)
def config(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) setConfig(ID) configBool = getConfig(ID) currentMoney = str(request.form['currentMoney']) monthIncome = str(request.form['monthIncome']) otherIncome = str(request.form['otherIncome']) savings = str(request.form['savings']) savingPercent = str(request.form['savingPercent']) addMoneyTable(ID, currentMoney,monthIncome,otherIncome,savings,savingPercent) entertain = str(request.form['entertainment']) eatOut = str(request.form['eatOut']) shop = str(request.form['shop']) misc = str(request.form['misc']) event = str(request.form['event']) grocery = str(request.form['grocery']) addAllocateTable(ID, entertain, eatOut, shop, misc, grocery, event) try: moneyTable = getMoneyTable(ID) except: moneyTable = {'otherIncome': 0, 'currentMoney': 0, 'savings': 0, 'monthIncome': 0, 'savingPercent': 0} return redirect(url_for('home'))
def logout(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) session.pop('user') flash('You have been logged out successfully') return redirect(url_for('root'))
def stocks(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) stockData = getAllStocks(ID) print stockData return render_template("stocks.html", stocksD = stockData)
def new(): title = request.form['title'] print title user = getUserID(session['user']) content = request.form['newStoryText'] print content addStory(title, user, content) flash('You have successfully created a new story. Watch its progress below!') return redirect(url_for("home"))
def fixcost(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) fixedName = request.form['fixedName'] fixedAmt = request.form['fixedAmt'] fixedtype = request.form['type'] fixedDesc = request.form['fixedDesc'] addFixCost(ID, fixedName, fixedAmt, fixedtype, fixedDesc) return redirect(url_for('root'))
def varcost(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) expName = request.form['expName'] expAmt = request.form['expAmt'] exptype = request.form['type'] expDesc = request.form['expDesc'] addVarCost(ID, expName,exptype, expAmt, expDesc) return redirect(url_for('root'))
def contribute(): if 'user' in session: thisStory = request.form['StoryID'] #print thisStory nextChapter = request.form['storyUp'] #print nextChapter addUpdate(thisStory, nextChapter, getUserID(session['user'])) flash('Your contribution was successful! You may now view the whole story!!!') #print hasContributed(getUserID(session['user']),thisStory) return redirect(url_for("home")) #return "in progress..." else: return redirect(url_for("root"))
def stockdisplay(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) stockName = request.form['stockName'] period = request.form['period'] period = "TIME_SERIES_" + period try: data = get_last_days(stockName, period, 12) return render_template('stockDisplay.html', data_var = data, stockNamez = stockName) except: flash("This stock does not exist") return redirect( url_for('stocks'))
def stockpurchase(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) stockName = request.form['stockName'] numStocks = request.form['numStocks'] try: data = get_last_days(stockName, "TIME_SERIES_DAILY", 1) except: flash("That stock does not exist. Some examples of ones that exist are MSFT and AAPL.") return redirect( url_for('stocks')) keys = data.keys() price = data[keys[0]]["4. close"] addStock(ID, stockName, int(numStocks), int(float(price))) flash("Bought " + str(numStocks) + " shares of " + stockName) return redirect( url_for('stocks'))
def stocksell(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) stockName = request.form['stockName'] numStocks = int(request.form['numStocks']) try: data = get_last_days(stockName, "TIME_SERIES_DAILY", 1) except: flash("That stock does not exist. Some examples of ones that exist are MSFT and AAPL.") return redirect( url_for('stocks')) keys = data.keys() price = data[keys[0]]["4. close"] try: stockData = getStock(ID, stockName) except: flash("You don't own this stock") return redirect( url_for('stocks')) numOwned = int(stockData["currentShares"]) #print numOwned if numOwned < numStocks: flash("You cannot sell more than you own.") else: flash("Sold " + str(numStocks) + " shares of " + stockName) removeStock(ID, stockName, int(numStocks), int(float(price))) return redirect( url_for('stocks'))
def removefix(): ID = getUserID(session['user']) for fixedID in request.form: removeFixedCost(ID, fixedID) return redirect(url_for('settings'))
def removevar(): ID = getUserID(session['user']) for expID in request.form: removeVarCost(ID, expID) return redirect(url_for('settings'))
def home(): try: ID = getUserID(session['user']) except: return redirect( url_for('root')) try: bigUpdater(ID) except: pass configBool = getConfig(ID) vartableraw = getAllVarCost(ID) vartable = addZero(vartableraw,"var") fixtable = addZero(getAllFixCost(ID),"fix") vartableJS = [] try: for each in vartableraw: tempd = {} filterstuff = filter(lambda person: person['expType'] == each['expType'], vartableJS) if not filterstuff: tempd['expType'] = each['expType'] tempd['expAmt'] = int(each['expAmt']) else: vartableJS.remove(filterstuff[0]) tempd['expType'] = each['expType'] tempd['expAmt'] = int(each['expAmt']) + filterstuff[0]['expAmt'] vartableJS.append(tempd) vartableJS = sorted(vartableJS, key=lambda d: int(d["expAmt"])) except: pass try: moneyTable = getMoneyTable(ID) moneyTable['currentMoney'] = '${:,.2f}'.format(float(moneyTable['currentMoney'])) moneyTable['savings'] = '${:,.2f}'.format(float(moneyTable['savings'])) except: moneyTable = {'otherIncome': 0, 'currentMoney': 0, 'savings': 0, 'monthIncome': 0, 'savingPercent': 0} if vartable == None: vartable = [] if fixtable == None: fixtable = [] graphData = getAllUpdateTable(ID) years = [] months = [] days = [] dates = [] currMon = [] saving = [] try: for dict in graphData: years.append(dict['year']) months.append(dict['month']) days.append(dict['day']) currMon.append(dict['currentMoney']) saving.append(dict['savings']) except: pass length = len(years) i = 0 while i < length: date = str(years[i]) + "-" + add_zero(str(months[i])) + "-" + add_zero(str(days[i])) dates.append(date) i += 1 gData = {} i = 0 while i < length: gData[dates[i]] = currMon[i] i += 1 print "gData" print gData g_keys = sorted(gData) print "g_keys" print g_keys return render_template("home.html",config=configBool, vartable = vartable, fixtable = fixtable, moneyTable = moneyTable, data_var = gData, data_k = g_keys, vartableJS = vartableJS)
def home(): if 'user' in session: cursor = seeStories() entries = [dict(storyID=str(entry[0]), title=str(entry[1]), author=str(getName(str(entry[2]))), option=hasContributed(getUserID(session['user']),int(entry[0]))) for entry in cursor.fetchall()] #print "Current userID:" #print getUserID(session['user']) #print "Has user 0 contributed to story 0:" #print hasContributed(getUserID(session['user']), 2) return render_template("home.html", code=Markup(buildTable(entries,session['user']))) else: return redirect(url_for("root"))