diff --git a/budget.py b/budget.py
index 24a4320..6837337 100644
--- a/budget.py
+++ b/budget.py
@@ -7,12 +7,37 @@ DB = "budget.db"
def get_balance():
with sqlite3.connect(DB) as conn:
- cur = conn.execute("SELECT COALESCE(SUM(amount), 0) FROM entries")
+ cur = conn.execute("SELECT COALESCE(SUM(amount), 0) FROM entries WHERE account = 'CURRENT'")
+ return cur.fetchone()[0]
+
+ def get_savings():
+ with sqlite3.connect(DB) as conn:
+ cur = conn.execute("SELECT COALESCE(SUM(amount), 0) FROM entries WHERE account = 'SAVINGS'")
+ return cur.fetchone()[0]
+
+ def get_isa212():
+ with sqlite3.connect(DB) as conn:
+ cur = conn.execute("SELECT COALESCE(SUM(amount), 0) FROM entries WHERE account = 'ISA-T212'")
+ return cur.fetchone()[0]
+
+ def get_isa_barc():
+ with sqlite3.connect(DB) as conn:
+ cur = conn.execute("SELECT COALESCE(SUM(amount), 0) FROM entries WHERE account = 'ISA-BARC'")
return cur.fetchone()[0]
def get_month_total():
with sqlite3.connect(DB) as conn:
- cur = conn.execute("SELECT total_amount FROM v_current_period_total")
+ cur = conn.execute("SELECT total_amount FROM v_current_budget_spend")
+ return cur.fetchone()[0]
+
+ def get_budget_average():
+ with sqlite3.connect(DB) as conn:
+ cur = conn.execute("SELECT average_amount FROM v_budget_3m_average")
+ return cur.fetchone()[0]
+
+ def get_projected_remaining():
+ with sqlite3.connect(DB) as conn:
+ cur = conn.execute("SELECT projected_balance FROM v_projected_balance")
return cur.fetchone()[0]
HTML = """
@@ -161,11 +186,21 @@ class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
balance = get_balance()
+ savings = get_savings()
+ tisa = get_isa212()
+ bisa = get_isa_barc()
month = get_month_total()
+ budget = get_budget_average()
+ projected = get_projected_remaining()
page = HTML.format(
balance=balance,
+ savings=savings,
+ tisa=tisa,
+ bisa=bisa,
month=month,
+ budget=budget,
+ projected=projected,
)
self.send_response(200)