Cybrkyd's Git Repositories

python-budget - commit: 6f7f97e

commit 6f7f97e62c2d911c97458c171a4147797f5d989f01e4f2ed7b9c193493c7ca02
author Cybrkyd <git@cybrkyd.com> 2026-06-03 11:37:09 +0100
committer Cybrkyd <git@cybrkyd.com> 2026-06-03 11:37:09 +0100

Commit Message

Add accounts and analytics to dashboard

- Balance queries are CURRENT, SAVINGS, ISA-T212, and ISA-BARC accounts
- Replace month total view with v_current_budget_spend
- Add budget average from 3-month rolling view
- Add projected remaining balance for current period

📊 Diffstat

budget.py 39
1 files changed, 37 insertions(+), 2 deletions(-)

Diff

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)