-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
26 lines (25 loc) · 793 Bytes
/
api.py
File metadata and controls
26 lines (25 loc) · 793 Bytes
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
import mysql.connector
import os
def call_proc(name, args=()):
try:
db = mysql.connector.connect(
host=os.environ.get("DB_HOST"),
database=os.environ.get("DB_NAME"),
user=os.environ.get("DB_USER"),
password=os.environ.get("DB_PASSWORD")
)
cursor = db.cursor()
cursor.callproc(name, args)
db.commit()
result = None
for stored_result in cursor.stored_results():
result = stored_result
break
output = []
if result:
columns = [data[0] for data in result.description]
for row in result.fetchall():
output.append(dict(zip(columns, row)))
return output
except:
return [{"result": "failure"}]