def history(): """Show history of transactions""" # Query the DB for symbol, num of share, curr_price, transacted time for the given user uid = dict(cuid=session['user_id']) st = db.execute("SELECT ticker, CASE WHEN trans_detail = 'by' THEN num_shares::text ELSE '-' || num_shares::text END AS num_shares, price_atm, purchase_time FROM transaction WHERE cuid=:cuid ORDER BY purchase_time desc", uid).fetchall() keys = ("ticker", "num_shares", "price_atm", "purchase_time") share_trans = [dict(zip(keys, values)) for values in st] history = transaction(share_trans) return render_template("history.html", history=history)
def addincome(): """Let the user add funds""" accountsdict = db.execute( "SELECT account_name FROM accounts WHERE user_id = :user_id", user_id=session["user_id"]) accounts = [] for i in range(len(accountsdict)): accounts.append(accountsdict[i]['account_name']) if request.method == "POST": account = request.form.get('account') return transaction(accounts, account, db, 1) else: return render_template("addincome.html", accounts=accounts)
def transfer(): """Transfer funds among accounts""" accountsdict = db.execute( "SELECT account_name FROM accounts WHERE user_id = :user_id", user_id=session["user_id"]) accounts = [] for i in range(len(accountsdict)): accounts.append(accountsdict[i]['account_name']) if request.method == "POST": origin_account = request.form.get('origin account') if origin_account not in accounts: return apology("Must enter existing account", 400) else: transaction(accounts, origin_account, db, -1) destination_account = request.form.get('destination account') return transaction(accounts, destination_account, db, 1) else: return render_template("transfer.html", accounts=accounts)
sequence = 1 # retrieve the manifest from the running emulator instance manifest = getManifest(sock, sequence) # create a Request message request = remotecontrolportapi_pb2.Request() # set the Request sequence number sequence += 1 request.sequence = sequence # set the Request type request.type = remotecontrolportapi_pb2.Request.TYPE_REQUEST_QUERY # set the Request Query type request.query.type = remotecontrolportapi_pb2.TYPE_QUERY_STATISTIC # for this example, set the target build id to the smallest build id # component contained in the smallest NEM id running in the emulator request.query.statistic.buildId = max( [x.buildId for x in manifest[max(manifest)]]) print '-' * 25, '\n', 'request\n', '-' * 25 print request response = transaction(sock, request) print '-' * 25, '\n', 'response\n', '-' * 25 print response
manifest = helpers.getManifest(sock, sequence) # create a Request message request = remotecontrolportapi_pb2.Request() # set the Request type request.type = remotecontrolportapi_pb2.Request.TYPE_REQUEST_UPDATE # set the Request Update type request.update.type = remotecontrolportapi_pb2.TYPE_UPDATE_STATISTICCLEAR # set the target build id to the smallest build id component contained # in the smallest NEM id running in the emulator request.update.statisticClear.buildId = min( [x.buildId for x in manifest[min(manifest)]]) # attempt to clear a non existent statistic request.update.statisticClear.names.append('foo') # set the Request sequence number sequence += 1 request.sequence = sequence print '-' * 25, '\n', 'request\n', '-' * 25 print request response = helpers.transaction(sock, request) print '-' * 25, '\n', 'response\n', '-' * 25 print response