closes #3, fix bug with user creation
This commit is contained in:
@@ -25,12 +25,12 @@ class Database:
|
||||
try:
|
||||
os.makedirs(config.database.path)
|
||||
except FileNotFoundError:
|
||||
print(self.db_path)
|
||||
dbg(self.db_path)
|
||||
if not os.path.exists(config.database.backupLocation):
|
||||
os.makedirs(config.database.backupLocation)
|
||||
|
||||
#if main path does not exist, try to create it. if that fails, use the backuplocation
|
||||
print(self.db_path)
|
||||
dbg(self.db_path)
|
||||
self.checkDatabaseStatus()
|
||||
|
||||
def handle_folder_reachability(self, original_path, backup_path):
|
||||
@@ -59,7 +59,7 @@ class Database:
|
||||
return backup_path +"/" + FILE
|
||||
|
||||
else:
|
||||
print("Original Path Exists, ")
|
||||
dbg("Original Path Exists, using this path")
|
||||
# Original folder is reachable, check for backup
|
||||
if os.path.exists(backup_file):
|
||||
# Restore backup
|
||||
@@ -125,7 +125,7 @@ class Database:
|
||||
|
||||
def createDatabase(self):
|
||||
log.info("Creating Database")
|
||||
# print("Creating Database")
|
||||
#print("Creating Database")
|
||||
if not os.path.exists(self.db_path):
|
||||
os.makedirs(self.db_path)
|
||||
conn = self.connect()
|
||||
@@ -197,6 +197,15 @@ class Database:
|
||||
return False
|
||||
self.close_connection(conn)
|
||||
return True
|
||||
|
||||
def getUserBy(self, key, value) -> User:
|
||||
conn = self.connect()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(f"SELECT * FROM users WHERE {key} = '{value}'")
|
||||
result = cursor.fetchone()
|
||||
self.close_connection(conn)
|
||||
user = User(userid=result[1], username=result[2], email=result[3], id=result[0])
|
||||
return user
|
||||
|
||||
def getUser(self, user_id) -> User:
|
||||
conn = self.connect()
|
||||
@@ -204,9 +213,9 @@ class Database:
|
||||
cursor.execute(f"SELECT * FROM users")
|
||||
result = cursor.fetchall()
|
||||
self.close_connection(conn)
|
||||
print(result)
|
||||
|
||||
for res in result:
|
||||
if res[0] == user_id:
|
||||
if res[1] == user_id:
|
||||
user = User(userid=res[1], username=res[2], email=res[3], id=res[0])
|
||||
dbg(f"Returning User {user}")
|
||||
log.info(f"Returning User {user}")
|
||||
@@ -332,7 +341,7 @@ class Database:
|
||||
cursor.execute(query)
|
||||
result = cursor.fetchone()
|
||||
signature = result[1]
|
||||
# print(signature)
|
||||
#print(signature)
|
||||
query = f"SELECT * FROM media WHERE signature LIKE '%{signature}%'"
|
||||
cursor.execute(query)
|
||||
result = cursor.fetchall()
|
||||
@@ -452,7 +461,7 @@ class Database:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
result = cursor.fetchone()
|
||||
print(result)
|
||||
dbg("Result", response=result)
|
||||
self.close_connection(conn)
|
||||
if result is not None:
|
||||
return result[0]
|
||||
|
||||
Reference in New Issue
Block a user