Update dashboard.py

This commit is contained in:
Donald Zou 2024-12-29 15:57:57 +08:00
parent 812060240f
commit ccfc1ad166

View File

@ -414,7 +414,7 @@ class PeerShareLinks:
self.Links.append(PeerShareLink(*link)) self.Links.append(PeerShareLink(*link))
def getLink(self, Configuration: str, Peer: str) -> list[PeerShareLink]: def getLink(self, Configuration: str, Peer: str) -> list[PeerShareLink]:
self.__getSharedLinks() # self.__getSharedLinks()
return list(filter(lambda x : x.Configuration == Configuration and x.Peer == Peer, self.Links)) return list(filter(lambda x : x.Configuration == Configuration and x.Peer == Peer, self.Links))
def getLinkByID(self, ShareID: str) -> list[PeerShareLink]: def getLinkByID(self, ShareID: str) -> list[PeerShareLink]:
@ -2026,25 +2026,25 @@ class EmailSender:
Database Connection Functions Database Connection Functions
""" """
# sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False) sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
# sqldb.row_factory = sqlite3.Row sqldb.row_factory = sqlite3.Row
# cursor = sqldb.cursor() # cursor = sqldb.cursor()
def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'))
sqldb.row_factory = sqlite3.Row
cursor = sqldb.cursor()
# sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'))
# sqldb.row_factory = sqlite3.Row
# cursor = sqldb.cursor()
result = []
with sqldb: with sqldb:
try: try:
print("[WGDashboard] SQLite Select" + " | Statement: " + statement)
cursor = sqldb.cursor() cursor = sqldb.cursor()
sqldb.close() result = cursor.execute(statement, paramters)
return cursor.execute(statement, paramters)
except Exception as error: except Exception as error:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement) print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
sqldb.close() return result
return []
def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db')) sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'))
@ -2059,7 +2059,7 @@ def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
# sqldb.commit() # sqldb.commit()
except Exception as error: except Exception as error:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement) print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
sqldb.close() sqldb.close()
DashboardConfig = DashboardConfig() DashboardConfig = DashboardConfig()