-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_user.py
More file actions
36 lines (32 loc) · 1.29 KB
/
check_user.py
File metadata and controls
36 lines (32 loc) · 1.29 KB
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
import sqlite3
class user:
def __init__(self, studentcursor, projectdb):
self.studentcursor = studentcursor
self.projectdb = projectdb
def format_list(self, list):
list = [str(item) for item in list]
new_list = '\n'.join(list)
new_list = new_list.replace('[', '')
new_list = new_list.replace(']', '')
new_list = new_list.replace("'", "")
new_list = new_list.replace('(', '')
new_list = new_list.replace(')', '')
new_list = new_list.replace(',', '')
return new_list
def create_user(self, username):
try:
#check to see if the user exists in the database
self.studentcursor.execute('SELECT username FROM user')
users = self.studentcursor.fetchall()
users = self.format_list(users)
if username in users:
#self.studentcursor.close()
return True, username
else:
self.studentcursor.execute('INSERT INTO user (username) VALUES (?)', (username,))
self.projectdb.commit()
print('User inserted successfully')
return True, username
except sqlite3.Error as err:
print(f'Error: {err}')
return False