File size: 872 Bytes
d3f795d |
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 |
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()
|