-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_wrapper.py
31 lines (28 loc) · 1.08 KB
/
db_wrapper.py
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
import MySQLdb
import discord
import asyncio
from datetime import datetime
class DB_Wrapper:
def __init__(self, user, passwd, host, db):
self.user = user
self.passwd = passwd
self.host = host
self.db = db
return
async def execute(self, client, member, sql_command, notify):
try:
db_connection = MySQLdb.connect(user=self.user, passwd=self.passwd, host=self.host, db=self.db, charset="utf8mb4")
cursor = db_connection.cursor()
cursor.execute(sql_command)
result = cursor.fetchall()
db_connection.commit()
cursor.close()
db_connection.close()
except Exception as e:
time = str(datetime.now())
print(time+": failed to properly execute DB command: "+sql_command)
print("The exception that occurred was: "+str(e))
if notify:
await client.send_message(member, "I had some trouble with a database query. Please ask Chish#2578 to check the logs at time "+time)
return
return result