Compare commits
No commits in common. "7e17c716101c521f8cd78c565eee96635bd25e2c" and "4f7b6de5a659795630de36dfbcc4b052b386289f" have entirely different histories.
7e17c71610
...
4f7b6de5a6
33
Config.py
33
Config.py
|
@ -1,33 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from json import load as jsonLoad
|
||||
from TYPES import DirParserTypes, LogTypes
|
||||
|
||||
CFG_PATH = "config.json"
|
||||
|
||||
|
||||
def loadCFG(config_path: str) -> dict:
|
||||
with open(config_path, "r") as cfg:
|
||||
return jsonLoad(cfg)
|
||||
|
||||
|
||||
def loadParser(options: dict) -> tuple:
|
||||
dirParser = None
|
||||
parser_value = options["Main"]["DirParser"]
|
||||
for av_parser in DirParserTypes:
|
||||
if parser_value == av_parser.value:
|
||||
dirParser = av_parser
|
||||
if dirParser is None:
|
||||
raise Exception(f"Directory parser '{parser_value}' not found")
|
||||
else:
|
||||
match dirParser:
|
||||
case DirParserTypes.Jellyfin:
|
||||
JellyfinConfig = {}
|
||||
for i in options["JellyfinConfig"].keys():
|
||||
JellyfinConfig[i] = options["JellyfinConfig"][i]
|
||||
return dirParser, JellyfinConfig
|
||||
|
||||
|
||||
configuration = loadCFG(CFG_PATH)
|
||||
|
||||
dirParser, JellyfinConfig = loadParser(configuration)
|
||||
DBPath = configuration["Main"]["DBPath"]
|
33
DataBase.py
33
DataBase.py
|
@ -1,33 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from sqlite3 import connect as sqconnect
|
||||
|
||||
|
||||
class DataBase(object):
|
||||
|
||||
def __init__(self, path: str, table: str) -> None:
|
||||
self.path = path
|
||||
self.table = table
|
||||
|
||||
def __execute(self, request: str, additional=None):
|
||||
with sqconnect(self.path) as db:
|
||||
cursor = db.cursor()
|
||||
if additional is not None:
|
||||
cursor.execute(request, additional)
|
||||
else:
|
||||
cursor.execute(request)
|
||||
db.commit()
|
||||
|
||||
def createTable(self, table_content: str) -> None:
|
||||
self.__execute(f'''
|
||||
CREATE TABLE IF NOT EXISTS {self.table}(
|
||||
id INTEGER PRIMARY KEY,
|
||||
{table_content}
|
||||
)
|
||||
''')
|
||||
|
||||
def insert(self, data: dict) -> None:
|
||||
fields = ", ".join(list(data.keys()))
|
||||
values = list(data.values())
|
||||
self.__execute(f'''
|
||||
INSERT INTO {self.table} ({fields}) VALUES ({str("?," * len(data))[:-1]})
|
||||
''', tuple(values))
|
|
@ -15,7 +15,7 @@ class DirectoryGetter(object):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
def validation(self) -> bool:
|
||||
def CheckAvailability(self) -> bool:
|
||||
"""
|
||||
Checks if the directory parsing method is available
|
||||
:return: boolean check result
|
||||
|
@ -26,14 +26,12 @@ class Jellyfin(DirectoryGetter):
|
|||
def __init__(self, url: str, api_key: str) -> None:
|
||||
self.url = url
|
||||
self.api_key = api_key
|
||||
if self.url[-1] == "/":
|
||||
self.url = self.url[:-1]
|
||||
if not (self.validation()):
|
||||
raise Exception("Error connecting to JellyfinAPI")
|
||||
|
||||
def validation(self) -> bool:
|
||||
def CheckAvailability(self) -> bool:
|
||||
if self.__get("Library/VirtualFolders").status_code == 200:
|
||||
return True
|
||||
else:
|
||||
raise Exception("Error connecting to JellyfinAPI")
|
||||
|
||||
def __get(self, api_path: str) -> Response:
|
||||
request = req_get(f"{self.url}/{api_path}?api_key={self.api_key}")
|
||||
|
@ -42,7 +40,7 @@ class Jellyfin(DirectoryGetter):
|
|||
case 200:
|
||||
return request
|
||||
case 401:
|
||||
raise Exception("Error 401: Authorization error, check API key")
|
||||
raise Exception("Error 401: Authorization error, check api key")
|
||||
case 403:
|
||||
raise Exception("Error 403: Forbidden")
|
||||
case 404:
|
||||
|
|
31
LogSystem.py
31
LogSystem.py
|
@ -1,31 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from datetime import datetime
|
||||
from TYPES import LogTypes
|
||||
from DataBase import DataBase
|
||||
from Config import DBPath
|
||||
|
||||
|
||||
class Log(object):
|
||||
|
||||
def __init__(self, logtype: LogTypes, location: str, message: str) -> None:
|
||||
self.logtype = logtype
|
||||
self.location = location
|
||||
self.msg = message
|
||||
self.toDB()
|
||||
|
||||
date = datetime.now().date()
|
||||
time = datetime.now().time().strftime("%H:%M:%S")
|
||||
|
||||
def __str__(self):
|
||||
return f"[{self.date} | {self.time}] [{self.logtype.value}] [{self.location}] {self.msg}"
|
||||
|
||||
def toDB(self):
|
||||
db = DataBase(DBPath, "logs")
|
||||
db.createTable("date TEXT, time TEXT, type TEXT, location TEXT, message TEXT")
|
||||
db.insert({
|
||||
"date": self.date,
|
||||
"time": self.time,
|
||||
"type": self.logtype.value,
|
||||
"location": self.location,
|
||||
"message": self.msg
|
||||
})
|
11
TYPES.py
11
TYPES.py
|
@ -1,12 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class DirParserTypes(Enum):
|
||||
Jellyfin = "Jellyfin"
|
||||
|
||||
|
||||
class LogTypes(Enum):
|
||||
LOG = "Log"
|
||||
ERROR = "Error"
|
||||
WARN = "Warning"
|
||||
|
|
11
config.json
11
config.json
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"Main": {
|
||||
"DirParser": "Jellyfin",
|
||||
"DBPath": "/etc/qbitbot/botdb.db"
|
||||
},
|
||||
|
||||
"JellyfinConfig": {
|
||||
"ServerURL": "https://yourdomain.com",
|
||||
"APIKey": "youaractualjellyfintoken"
|
||||
}
|
||||
}
|
Reference in New Issue