mirror of
https://github.com/agresdominik/predictify.git
synced 2026-04-21 17:55:49 +00:00
Refactored logger
This commit is contained in:
+15
-6
@@ -1,10 +1,13 @@
|
|||||||
import logging as log
|
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from logger import LoggerWrapper
|
||||||
|
|
||||||
DATABASE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data', 'spotify_scraped.db')
|
DATABASE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data', 'spotify_scraped.db')
|
||||||
|
|
||||||
|
log = LoggerWrapper()
|
||||||
|
|
||||||
|
|
||||||
class Table(Enum):
|
class Table(Enum):
|
||||||
TRACK_INFORMATION = "track_information"
|
TRACK_INFORMATION = "track_information"
|
||||||
@@ -82,6 +85,7 @@ class Database:
|
|||||||
|
|
||||||
# Commit the changes
|
# Commit the changes
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
log.debug("Initialised tables")
|
||||||
|
|
||||||
def add_row(self, table: Table, values):
|
def add_row(self, table: Table, values):
|
||||||
"""Add a new row into the specified table"""
|
"""Add a new row into the specified table"""
|
||||||
@@ -91,13 +95,17 @@ class Database:
|
|||||||
self.cursor.execute(query, values)
|
self.cursor.execute(query, values)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(f"Error: {e}")
|
log.error(f"Error while inserting row into table {table.value}: {e}")
|
||||||
|
|
||||||
def read_all_rows(self, table: Table, column: str = "*"):
|
def read_all_rows(self, table: Table, column: str = "*"):
|
||||||
"""Read all rows from the specified table"""
|
"""Read all rows from the specified table"""
|
||||||
self.cursor.execute(f"SELECT {column} FROM {table.value}")
|
try:
|
||||||
rows = self.cursor.fetchall()
|
self.cursor.execute(f"SELECT {column} FROM {table.value}")
|
||||||
return rows
|
rows = self.cursor.fetchall()
|
||||||
|
return rows
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"Error while reading all rows from table {table.value}: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the database connection"""
|
"""Close the database connection"""
|
||||||
@@ -125,5 +133,6 @@ class Database:
|
|||||||
rows = self.cursor.fetchall()
|
rows = self.cursor.fetchall()
|
||||||
return rows
|
return rows
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Error retrieving total overview: {e}")
|
log.error(f"Error retrieving total overview: {e}"
|
||||||
|
f"\nQuery Executed: {query}")
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user