-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbOperations.py
52 lines (40 loc) · 1.27 KB
/
dbOperations.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import mysql.connector
import os
from dotenv import load_dotenv
load_dotenv()
sql_pass = os.getenv("PASSWORD")
mydb = mysql.connector.connect(
host = "localhost",
user = "root",
password = sql_pass,
database = "aibotdb"
)
mycursor = mydb.cursor()
def insertUserInfo(chat_id, u_name, f_name, l_name):
sql = "INSERT INTO userinfo (chat_id, username, first_name, last_name) VALUES (%s, %s, %s, %s)"
val = (chat_id, u_name, f_name, l_name)
mycursor.execute(sql, val)
mydb.commit()
return
def checkUserInfo(chatid):
sql = f'SELECT chat_id FROM userinfo WHERE chat_id = {chatid};'
mycursor.execute(sql)
result = mycursor.fetchone()
return result
def deleteUserInfo(chatid):
sql = f'DELETE FROM userinfo WHERE chat_id = {chatid};'
mycursor.execute(sql)
mydb.commit()
return
def getUserInfo(chatid):
sql = f'SELECT first_name FROM userinfo WHERE chat_id = {chatid};'
mycursor.execute(sql)
name = mycursor.fetchone()
return name
# Inserting the intents data to train the model
def insertIntentsData(tag, patterns, responses, json_formate):
sql = "INSERT INTO intents_data (tag, patterns, responses, json_formate) VALUES (%s, %s, %s, %s)"
val = (tag, patterns, responses, json_formate)
mycursor.execute(sql, val)
mydb.commit()
return