From 6e3bc7d7aac3bc2d2711d8f7be2d26ec63bba040 Mon Sep 17 00:00:00 2001 From: kukemuna Date: Thu, 25 Apr 2024 23:41:15 +0300 Subject: [PATCH] automated commit by check50 [check50=True] --- app.py | 33 +++++++++--------- finance.db | Bin 20480 -> 20480 bytes .../4c5bec882c6cb133810c5c1724f348ac | Bin 46 -> 46 bytes 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index e6b8d3f..ff088c5 100644 --- a/app.py +++ b/app.py @@ -68,7 +68,7 @@ def buy(): return render_template("buy.html") else: symbol = request.form.get("symbol") - shares = int(request.form.get("shares")) + shares = request.form.get("shares") if not symbol: return apology("Not Symbol") @@ -78,25 +78,26 @@ def buy(): if stock == None: return apology("Symbol not found") - transaction_value = shares * stock["price"] + if not shares == "": + transaction_value = int(shares) * stock["price"] - user_id = session["user_id"] - user_cash_db = db.execute("SELECT cash FROM users WHERE id = ?", user_id) - user_cash = user_cash_db[0]["cash"] + user_id = session["user_id"] + user_cash_db = db.execute("SELECT cash FROM users WHERE id = ?", user_id) + user_cash = user_cash_db[0]["cash"] - if user_cash < transaction_value: - return apology("U broke, m8!") + if user_cash < transaction_value: + return apology("U broke, m8!") - free_cash = user_cash - transaction_value + free_cash = user_cash - transaction_value - db.execute("UPDATE users SET cash = ? WHERE id = ?", free_cash, user_id) + db.execute("UPDATE users SET cash = ? WHERE id = ?", free_cash, user_id) - date = datetime.datetime.now() + date = datetime.datetime.now() - db.execute("INSERT INTO transactions (user_id, symbol, shares, price, date) VALUES (?, ?, ?, ?, ?)", - user_id, stock["symbol"], shares, stock["price"], date) + db.execute("INSERT INTO transactions (user_id, symbol, shares, price, date) VALUES (?, ?, ?, ?, ?)", + user_id, stock["symbol"], shares, stock["price"], date) - flash("Bought!") + flash("Bought!") return redirect("/") # return apology("TODO") @@ -191,15 +192,15 @@ def register(): if request.method == "POST": # Ensure username was submitted if not request.form.get("username"): - return apology("must provide username", 403) + return apology("must provide username", 400) # Ensure password was submitted elif not request.form.get("password"): - return apology("must provide password", 403) + return apology("must provide password", 400) # Ensure password repeat matches if not request.form.get("password") == request.form.get("confirmation"): - return apology("passwords don't match", 403) + return apology("passwords don't match", 400) username = request.form.get("username") password = request.form.get("password") diff --git a/finance.db b/finance.db index 77daec9fef8c0ad8be191950036779ba00d541c5..48cecf219e80a97b64d6472cbdbd7d4c25d6a1d2 100644 GIT binary patch delta 190 zcmZozz}T>Wae_3X*F+g-Mz4(t=5lQQ7J;u@%R8QF~kd_scQ989+!>W|U*W@KPwqHAEHYh4|avd7FNcV>as`*S#T;evQ(F0XV}c_^OqR_pNldq delta 55 zcmV-70LcG