Cybrkyd's Git Repositories

python-budget - commit: e6ce807

commit e6ce807d78080a7d5c7d65bc88dea5c38a50adeb1912b7597f47bd81f459053c
author Cybrkyd <git@cybrkyd.com> 2026-05-29 15:38:32 +0100
committer Cybrkyd <git@cybrkyd.com> 2026-05-29 15:38:32 +0100

Commit Message

Database table

- Added credit and debit columns
- Auto post to respective column (+ or -)

📊 Diffstat

budget.py 14
1 files changed, 12 insertions(+), 2 deletions(-)

Diff

diff --git a/budget.py b/budget.py
index 7983e11..52c8cdb 100644
--- a/budget.py
+++ b/budget.py
@@ -12,6 +12,8 @@ def init_db():
conn.execute("""
CREATE TABLE IF NOT EXISTS entries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ credit REAL DEFAULT 0,
+ debit REAL DEFAULT 0,
amount REAL NOT NULL,
created_at TEXT NOT NULL
)
@@ -111,10 +113,18 @@ class Handler(BaseHTTPRequestHandler):
amount = float(data["amount"][0])
+ # Determine if the amount should be credit or debit
+ if amount > 0:
+ credit = amount
+ debit = 0
+ else:
+ credit = 0
+ debit = abs(amount)
+
with sqlite3.connect(DB) as conn:
conn.execute(
- "INSERT INTO entries(amount, created_at) VALUES (?, ?)",
- (amount, datetime.now().isoformat())
+ "INSERT INTO entries(credit, debit, amount, created_at) VALUES (?, ?, ?, ?)",
+ (credit, debit, amount, datetime.now().isoformat())
)
self.send_response(303)