-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
52 lines (46 loc) · 1.88 KB
/
db.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 pymysql.cursors
import genpass
class Database(object):
def __init__(self):
self.host = "localhost"
self.usrnme = "root"
self.pswrd = ""
self.dbnme = "twitter_analysis"
self.connection = pymysql.connect(host=self.host,
user=self.usrnme,
password=self.pswrd,
db=self.dbnme,
cursorclass=pymysql.cursors.DictCursor)
def con_auth(self, user_name, user_pass):
with self.connection.cursor() as cursor:
com = "SELECT * FROM users WHERE username='"+user_name+"'"
cursor.execute(com)
check = cursor.fetchone()
self.connection.commit()
try:
userpass = check["password"]
if genpass.check_password_hash(userpass, user_pass):
return check
except:
return None
def check_id(self, unique_id):
with self.connection.cursor() as cursor:
com = "SELECT * FROM sentiment_search WHERE unique_id='"+unique_id+"'"
try:
cursor.execute(com)
check = cursor.fetchone()
except:
return None
self.connection.commit()
return check
def insertid(self, unique_id, username):
with self.connection.cursor() as cursor:
sql = "INSERT INTO sentiment_search VALUES('"+unique_id+"', '"+username+"')"
cursor.execute(sql)
def register_user(self, name, contact, email, username, password):
with self.connection.cursor() as cursor:
gen_hash = genpass.User(username, password)
password = gen_hash.pw_hash
sql = "INSERT INTO users VALUES('"+username+"', '"+name+"', '"+contact+"', '"+email+"', '"+password+"')"
cursor.execute(sql)
self.connection.commit()