-
Notifications
You must be signed in to change notification settings - Fork 21
/
pillar.py
38 lines (27 loc) · 820 Bytes
/
pillar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
from cs50 import SQL
from helpers import lookup, usd
db = SQL("sqlite:///finance.db")
user_portfolio = db.execute(
"SELECT id, symbol, name, SUM(shares) as tshares FROM trades WHERE id = ? AND price>0 GROUP BY symbol ORDER BY shares DESC", 1)
current_worth = 0
for stock in user_portfolio:
stock_data = lookup(stock["symbol"])
stock["currentprice"] = stock_data["price"]
stock["totalprice"] = stock_data["price"] * stock["tshares"]
current_worth += stock["totalprice"]
user_cash = db.execute("SELECT * FROM users WHERE id = ?", 1)
print(user_portfolio[0], current_worth)
"""
def is_float(s):
try:
float(s)
return True
except ValueError:
return False
def is_int(s):
try:
int(s)
return True
except ValueError:
return False