DragonOsman

index route, pset7 Finance

Mar 13th, 2017
574
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @app.route("/")
  2. @login_required
  3. def index():
  4.     users_info = db.execute("SELECT * FROM users WHERE id=:uid", uid=session["user_id"])
  5.     transactions_info = db.execute("SELECT * FROM user_stocks WHERE user_id=:uid GROUP BY stock_symbol ORDER BY id", uid=session["user_id"])
  6.     grand_total = 0
  7.     total_price = []
  8.     for i in range(len(users_info)):
  9.         grand_total = users_info[i]["cash"]
  10.     no_of_shares_dict = {}
  11.     current_price_dict = {}
  12.     stock_names_dict = {}
  13.     if len(transactions_info) != 0:
  14.         for i in range(len(transactions_info)):
  15.             for j in range(len(users_info)):
  16.                 cash = users_info[j]["cash"]
  17.                
  18.         total_shares = 0
  19.         for i in range(len(transactions_info)):
  20.             if transactions_info[i]["stock_symbol"] not in no_of_shares_dict:
  21.                 for j in range(i, len(transactions_info)):
  22.                     if transactions_info[i]["stock_symbol"] == transactions_info[j]["stock_symbol"]:
  23.                         total_shares += transactions_info[j]["no_of_shares"]
  24.                 no_of_shares_dict.update({
  25.                     transactions_info[i]["stock_symbol"]: total_shares
  26.                 })
  27.                 total_shares = 0
  28.                
  29.         for key in no_of_shares_dict:
  30.             current_price_dict.update({
  31.                 key: lookup(key)["price"]
  32.             })
  33.            
  34.         for key in no_of_shares_dict:
  35.             stock_names_dict.update({
  36.                 key: lookup(key)["name"]
  37.             })
  38.            
  39.         for key in no_of_shares_dict:
  40.             total_price.append(lookup(key)["price"] * no_of_shares_dict.get(key))
  41.                        
  42.         for i in range(len(total_price)):
  43.             grand_total += total_price[i]
  44.    
  45.     return render_template("index.html", users_info=users_info, current_price_dict=current_price_dict, grand_total=grand_total,
  46.     no_of_shares_dict=no_of_shares_dict, stock_names_dict=stock_names_dict, total_price=total_price)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×