Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sqlite3
|
2 |
+
|
3 |
+
def generate_double_entry(text):
|
4 |
+
# Very basic logic, should improve using rules/keywords
|
5 |
+
if "furniture" in text:
|
6 |
+
return ("Office Furniture", "Cash", 1000)
|
7 |
+
elif "rent" in text:
|
8 |
+
return ("Rent Expense", "Bank", 2000)
|
9 |
+
else:
|
10 |
+
return ("Uncategorized Debit", "Uncategorized Credit", 0)
|
11 |
+
|
12 |
+
def save_transaction(debit, credit, amount, description):
|
13 |
+
conn = sqlite3.connect("db.sqlite")
|
14 |
+
cursor = conn.cursor()
|
15 |
+
cursor.execute("""
|
16 |
+
CREATE TABLE IF NOT EXISTS transactions (
|
17 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
18 |
+
debit TEXT, credit TEXT, amount REAL, description TEXT
|
19 |
+
)
|
20 |
+
""")
|
21 |
+
cursor.execute("""
|
22 |
+
INSERT INTO transactions (debit, credit, amount, description)
|
23 |
+
VALUES (?, ?, ?, ?)
|
24 |
+
""", (debit, credit, amount, description))
|
25 |
+
conn.commit()
|
26 |
+
conn.close()
|