mirror of https://github.com/me50/kukemuna.git
automated commit by check50 [check50=True]
This commit is contained in:
parent
b9530e6711
commit
8b9c1adadc
44
app.py
44
app.py
|
|
@ -78,28 +78,32 @@ def buy():
|
|||
if stock == None:
|
||||
return apology("Symbol not found")
|
||||
|
||||
if shares:
|
||||
transaction_value = float(shares) * stock["price"]
|
||||
if not shares or shares.isalpha() or not float(shares).is_integer():
|
||||
return apology("invalid shares")
|
||||
|
||||
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!")
|
||||
|
||||
free_cash = user_cash - transaction_value
|
||||
|
||||
db.execute("UPDATE users SET cash = ? WHERE id = ?", free_cash, user_id)
|
||||
|
||||
date = datetime.datetime.now()
|
||||
|
||||
db.execute("INSERT INTO transactions (user_id, symbol, shares, price, date) VALUES (?, ?, ?, ?, ?)",
|
||||
user_id, stock["symbol"], shares, stock["price"], date)
|
||||
|
||||
flash("Bought!")
|
||||
else:
|
||||
return apology("Missing shares", 400)
|
||||
if float(shares) > 0:
|
||||
transaction_value = float(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"]
|
||||
|
||||
if user_cash < transaction_value:
|
||||
return apology("U broke, m8!")
|
||||
|
||||
free_cash = user_cash - transaction_value
|
||||
|
||||
db.execute("UPDATE users SET cash = ? WHERE id = ?", free_cash, user_id)
|
||||
|
||||
date = datetime.datetime.now()
|
||||
|
||||
db.execute("INSERT INTO transactions (user_id, symbol, shares, price, date) VALUES (?, ?, ?, ?, ?)",
|
||||
user_id, stock["symbol"], shares, stock["price"], date)
|
||||
|
||||
flash("Bought!")
|
||||
else:
|
||||
return apology("Missing shares", 400)
|
||||
|
||||
return redirect("/")
|
||||
# return apology("TODO")
|
||||
|
|
|
|||
BIN
finance.db
BIN
finance.db
Binary file not shown.
Binary file not shown.
|
|
@ -10,7 +10,7 @@
|
|||
<input class="form-control mx-auto w-auto" autocomplete="off" autofocus="" name="symbol" placeholder="Symbol" type="text">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input class="form-control mx-auto w-auto" autocomplete="off" autofocus min="1" name="shares" placeholder="Shares" type="number">
|
||||
<input class="form-control mx-auto w-auto" autocomplete="off" autofocus min="1" name="shares" placeholder="Shares" type="text">
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Buy</button>
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Reference in New Issue