Add issue templates for bug reports and feature requests; implement logging in KomCache
This commit is contained in:
@@ -2,6 +2,12 @@ import sqlite3
|
||||
from komconfig import KomConfig, CONFIG_PATH
|
||||
from pathlib import Path
|
||||
import os
|
||||
import loguru
|
||||
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add("logs/cache.log", level="INFO", rotation="15MB", retention="1 week")
|
||||
log.add("logs/cli.log", rotation="15MB", retention="1 week") # type:ignore
|
||||
|
||||
|
||||
class KomCache:
|
||||
@@ -9,7 +15,6 @@ class KomCache:
|
||||
self.db_path = Path(db_path, "komcache.db")
|
||||
if "~" in str(self.db_path):
|
||||
self.db_path = os.path.expanduser(str(self.db_path))
|
||||
print(f"Database path: {self.db_path}")
|
||||
self.conn = sqlite3.connect(self.db_path)
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
@@ -54,12 +59,16 @@ class KomCache:
|
||||
args = []
|
||||
try:
|
||||
self.cursor.execute(query, args)
|
||||
return self.cursor.fetchall()[0]
|
||||
data = self.cursor.fetchall()
|
||||
if data:
|
||||
return data
|
||||
else:
|
||||
return None
|
||||
except sqlite3.Error as e:
|
||||
print(f"Error executing query: {e}")
|
||||
return []
|
||||
|
||||
def insert(self, query, args=None):
|
||||
def insert(self, query: str, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
try:
|
||||
@@ -75,12 +84,53 @@ class KomCache:
|
||||
args = []
|
||||
try:
|
||||
self.cursor.execute(query, args)
|
||||
log.debug("Query: {}, Args: {}".format(query, args))
|
||||
self.conn.commit()
|
||||
return True
|
||||
except sqlite3.Error as e:
|
||||
print(f"Error updating data: {e}")
|
||||
return False
|
||||
|
||||
def get_last_update_date(self, series_name: str) -> str:
|
||||
"""
|
||||
Get the last update date for a series.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
series_name : str
|
||||
The name of the series.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The last update date.
|
||||
"""
|
||||
query = "SELECT last_update_date FROM komgrabber WHERE series_name = ?"
|
||||
result = self.query(query, (series_name,))
|
||||
if result:
|
||||
return result[0][0]
|
||||
return ""
|
||||
|
||||
def fetch_one(self, query: str, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
try:
|
||||
self.cursor.execute(query, args)
|
||||
return self.cursor.fetchone()
|
||||
except sqlite3.Error as e:
|
||||
print(f"Error fetching one: {e}")
|
||||
return None
|
||||
|
||||
def fetch_all(self, query: str, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
try:
|
||||
self.cursor.execute(query, args)
|
||||
return self.cursor.fetchall()
|
||||
except sqlite3.Error as e:
|
||||
print(f"Error fetching one: {e}")
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example usage
|
||||
|
||||
Reference in New Issue
Block a user