Spaces:
Running on Zero
Running on Zero
Upload community_contributions/a3_igniters_sodiq/tools.py with huggingface_hub
Browse files
community_contributions/a3_igniters_sodiq/tools.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
|
| 3 |
+
DB_NAME = "support.db"
|
| 4 |
+
|
| 5 |
+
def query_db(query, params=()):
|
| 6 |
+
conn = sqlite3.connect(DB_NAME)
|
| 7 |
+
cursor = conn.cursor()
|
| 8 |
+
|
| 9 |
+
cursor.execute(query, params)
|
| 10 |
+
results = cursor.fetchall()
|
| 11 |
+
|
| 12 |
+
conn.commit()
|
| 13 |
+
conn.close()
|
| 14 |
+
|
| 15 |
+
return results
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def lookup_user_account(email):
|
| 19 |
+
|
| 20 |
+
result = query_db(
|
| 21 |
+
"SELECT email, plan, status, balance FROM users WHERE email=?",
|
| 22 |
+
(email,)
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
if not result:
|
| 26 |
+
return "User not found"
|
| 27 |
+
|
| 28 |
+
email, plan, status, balance = result[0]
|
| 29 |
+
|
| 30 |
+
return {
|
| 31 |
+
"email": email,
|
| 32 |
+
"plan": plan,
|
| 33 |
+
"status": status,
|
| 34 |
+
"balance_cents": balance
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def issue_refund(order_id):
|
| 39 |
+
|
| 40 |
+
order = query_db(
|
| 41 |
+
"SELECT id, status FROM orders WHERE id=?",
|
| 42 |
+
(order_id,)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if not order:
|
| 46 |
+
return "Order not found"
|
| 47 |
+
|
| 48 |
+
query_db(
|
| 49 |
+
"UPDATE orders SET status='refund_initiated' WHERE id=?",
|
| 50 |
+
(order_id,)
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
return {
|
| 54 |
+
"order_id": order_id,
|
| 55 |
+
"status": "refund initiated"
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def create_support_ticket(issue):
|
| 60 |
+
|
| 61 |
+
query_db(
|
| 62 |
+
"INSERT INTO tickets (issue,status) VALUES (?,?)",
|
| 63 |
+
(issue, "open")
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
ticket = query_db(
|
| 67 |
+
"SELECT id FROM tickets ORDER BY id DESC LIMIT 1"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
return {
|
| 71 |
+
"ticket_id": ticket[0][0],
|
| 72 |
+
"status": "created"
|
| 73 |
+
}
|