-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
34 lines (28 loc) · 1.1 KB
/
tools.py
File metadata and controls
34 lines (28 loc) · 1.1 KB
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
28
29
30
31
32
33
34
import sqlite3
import os
from typing import Dict
def setup_db():
"""Initialize SQLite DB with mock inventory."""
if os.path.exists('inventory.db'):
os.remove('inventory.db')
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute('''CREATE TABLE inventory
(item_name TEXT PRIMARY KEY, stock INTEGER)''')
# Mock data
c.execute("INSERT INTO inventory VALUES ('GadgetX', 100)")
c.execute("INSERT INTO inventory VALUES ('WidgetY', 50)")
c.execute("INSERT INTO inventory VALUES ('ThingZ', 0)")
c.execute("INSERT INTO inventory VALUES ('ServiceFee', 999)")
conn.commit()
conn.close()
def query_inventory(item_name: str) -> int:
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT stock FROM inventory WHERE item_name = ?", (item_name,))
result = c.fetchone()
conn.close()
return result[0] if result else -1
def mock_payment(vendor: str, amount: float) -> Dict:
print(f"[MOCK PAY] Processing payment of ${amount} to {vendor}...")
return {"status": "success", "transaction_id": "mock_tx_123"}