MCPcopy
hub / github.com/openai/swarm / add_purchase

Function add_purchase

examples/personal_shopper/database.py:84–111  ·  view source on GitHub ↗
(user_id, date_of_purchase, item_id, amount)

Source from the content-addressed store, hash-verified

82
83
84def add_purchase(user_id, date_of_purchase, item_id, amount):
85 conn = get_connection()
86 cursor = conn.cursor()
87
88 # Check if the purchase already exists
89 cursor.execute(
90 """
91 SELECT * FROM PurchaseHistory
92 WHERE user_id = ? AND item_id = ? AND date_of_purchase = ?
93 """,
94 (user_id, item_id, date_of_purchase),
95 )
96 if cursor.fetchone():
97 # print(f"Purchase already exists for user_id {user_id} on {date_of_purchase} for item_id {item_id}.")
98 return
99
100 try:
101 cursor.execute(
102 """
103 INSERT INTO PurchaseHistory (user_id, date_of_purchase, item_id, amount)
104 VALUES (?, ?, ?, ?)
105 """,
106 (user_id, date_of_purchase, item_id, amount),
107 )
108
109 conn.commit()
110 except sqlite3.Error as e:
111 print(f"Database Error: {e}")
112
113
114def add_product(product_id, product_name, price):

Callers 1

initialize_databaseFunction · 0.85

Calls 1

get_connectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…