-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.py
54 lines (48 loc) · 1.7 KB
/
sql.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
53
54
import mysql.connector as connector
con = connector.connect(host='localhost',
user='root',
password='',
database='chatbot')
cursor = con.cursor()
def add_keyword(userid,word):
Qstr = "delete from keywords where user_id={}".format(userid)
cursor.execute(Qstr)
con.commit()
Qstr = "insert into keywords values({},\"{}\")".format(userid,word)
cursor.execute(Qstr)
con.commit()
return word
def get_userid(username,password):
Qstr = "select user_id from userdata where username = \"{}\" and passkey = \"{}\"".format(username,password)
cursor.execute(Qstr)
rows = cursor.fetchall()
for row in rows:
return row[0]
def check_login(username, password):
Qstr = "SELECT username,passkey from userdata where username=\"" + str(username) + "\"" "and passkey=\"" + str(password) + "\""
cursor.execute(Qstr)
rows = cursor.fetchall()
if len(rows)==0:
return False
for row in rows:
if (username==row[0] and password==row[1]):
return True
return False
def add_signup(username,password):
Qstr = "SELECT username from userdata where username=\"" + str(username) + "\""
cursor.execute(Qstr)
rows = cursor.fetchall()
if len(rows)!=0:
return False
else:
Qstr = "insert into userdata(username,passkey) values(\"{}\",\"{}\")".format(username,password)
cursor.execute(Qstr)
con.commit()
return True
def get_keyword(userid):
Qstr = "select keyword from keywords where user_id = {}".format(userid)
cursor.execute(Qstr)
rows = cursor.fetchall()
for row in rows:
return str(row[0]).lower()
return "null"