test22 / utils.py
ZeeAI1's picture
Create utils.py
d3f795d verified
raw
history blame contribute delete
872 Bytes
import sqlite3
def generate_double_entry(text):
# Very basic logic, should improve using rules/keywords
if "furniture" in text:
return ("Office Furniture", "Cash", 1000)
elif "rent" in text:
return ("Rent Expense", "Bank", 2000)
else:
return ("Uncategorized Debit", "Uncategorized Credit", 0)
def save_transaction(debit, credit, amount, description):
conn = sqlite3.connect("db.sqlite")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
debit TEXT, credit TEXT, amount REAL, description TEXT
)
""")
cursor.execute("""
INSERT INTO transactions (debit, credit, amount, description)
VALUES (?, ?, ?, ?)
""", (debit, credit, amount, description))
conn.commit()
conn.close()