diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 890f166b..56499b5a 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -1,7 +1,7 @@ [tool.ruff] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. select = ["E", "F", "I"] -ignore = ['E501'] +ignore = ['E501', 'F401'] # Allow autofix for all enabled rules (when `--fix`) is provided. fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] diff --git a/backend/src/module/api/download.py b/backend/src/module/api/download.py index 64c0da1d..56a4c601 100644 --- a/backend/src/module/api/download.py +++ b/backend/src/module/api/download.py @@ -2,7 +2,7 @@ from fastapi import Depends, HTTPException, status from module.manager import SeasonCollector from module.models import BangumiData -from module.models.api import * +from module.models.api import RssLink from module.rss import analyser from module.security import get_current_user diff --git a/backend/src/module/api/program.py b/backend/src/module/api/program.py index 1b72035e..5e3cf6b5 100644 --- a/backend/src/module/api/program.py +++ b/backend/src/module/api/program.py @@ -61,7 +61,7 @@ async def stop(current_user=Depends(get_current_user)): @router.get("/api/v1/status", tags=["program"]) -async def status(current_user=Depends(get_current_user)): +async def program_status(current_user=Depends(get_current_user)): if not current_user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token" diff --git a/backend/src/module/checker/checker.py b/backend/src/module/checker/checker.py index bb2ed808..ac3cb036 100644 --- a/backend/src/module/checker/checker.py +++ b/backend/src/module/checker/checker.py @@ -1,6 +1,5 @@ -import os.path -from module.conf import DATA_PATH, settings +from module.conf import settings from module.downloader import DownloadClient from module.network import RequestContent diff --git a/backend/src/module/conf/config.py b/backend/src/module/conf/config.py index 0532a511..051feeca 100644 --- a/backend/src/module/conf/config.py +++ b/backend/src/module/conf/config.py @@ -17,7 +17,7 @@ try: logger.info("Can't find version info, use DEV_VERSION instead") CONFIG_PATH = "config/config_dev.json" else: - CONFIG_PATH = f"config/config.json" + CONFIG_PATH = "config/config.json" except ImportError: logger.info("Can't find version info, use DEV_VERSION instead") VERSION = "DEV_VERSION" @@ -38,7 +38,7 @@ class Settings(Config): config = json.load(f) config_obj = Config.parse_obj(config) self.__dict__.update(config_obj.__dict__) - logger.info(f"Config loaded") + logger.info("Config loaded") def save(self, config_dict: dict | None = None): if not config_dict: @@ -75,7 +75,7 @@ class Settings(Config): config_dict[key][attr_name] = self.__val_from_env(env, attr) config_obj = Config.parse_obj(config_dict) self.__dict__.update(config_obj.__dict__) - logger.info(f"Config loaded from env") + logger.info("Config loaded from env") @staticmethod def __val_from_env(env: str, attr: tuple): diff --git a/backend/src/module/database/bangumi.py b/backend/src/module/database/bangumi.py index e0e8c8be..3f8ad9fa 100644 --- a/backend/src/module/database/bangumi.py +++ b/backend/src/module/database/bangumi.py @@ -206,7 +206,7 @@ class BangumiDatabase(DataConnector): def not_complete(self) -> list[BangumiData]: # Find eps_complete = False condition = "eps_complete = 0" - data = self._search_datas( + self._search_datas( table_name=self.__table_name, condition=condition, ) diff --git a/backend/src/module/database/connector.py b/backend/src/module/database/connector.py index a72d92e8..7cdfdad3 100644 --- a/backend/src/module/database/connector.py +++ b/backend/src/module/database/connector.py @@ -124,7 +124,7 @@ class DataConnector: def _table_exists(self, table_name: str) -> bool: self._cursor.execute( - f"SELECT name FROM sqlite_master WHERE type='table' AND name=?;", + "SELECT name FROM sqlite_master WHERE type='table' AND name=?;", (table_name,), ) return len(self._cursor.fetchall()) == 1 diff --git a/backend/src/module/downloader/client/aria2_downloader.py b/backend/src/module/downloader/client/aria2_downloader.py index 7e755f11..2aa1788a 100644 --- a/backend/src/module/downloader/client/aria2_downloader.py +++ b/backend/src/module/downloader/client/aria2_downloader.py @@ -4,7 +4,6 @@ import time from aria2p import API, Client, ClientException from module.conf import settings -from module.downloader.exceptions import ConflictError logger = logging.getLogger(__name__) diff --git a/backend/src/module/downloader/client/qb_downloader.py b/backend/src/module/downloader/client/qb_downloader.py index 9dda692e..b18e2dcc 100644 --- a/backend/src/module/downloader/client/qb_downloader.py +++ b/backend/src/module/downloader/client/qb_downloader.py @@ -39,12 +39,12 @@ class QbDownloader: time.sleep(5) times += 1 except Forbidden403Error: - logger.error(f"Login refused by qBittorrent Server") - logger.info(f"Please release the IP in qBittorrent Server") + logger.error("Login refused by qBittorrent Server") + logger.info("Please release the IP in qBittorrent Server") break except APIConnectionError: - logger.error(f"Cannot connect to qBittorrent Server") - logger.info(f"Please check the IP and port in WebUI settings") + logger.error("Cannot connect to qBittorrent Server") + logger.info("Please check the IP and port in WebUI settings") time.sleep(10) times += 1 except Exception as e: diff --git a/backend/src/module/downloader/download_client.py b/backend/src/module/downloader/download_client.py index 32db35d6..7d0a4b1d 100644 --- a/backend/src/module/downloader/download_client.py +++ b/backend/src/module/downloader/download_client.py @@ -62,7 +62,7 @@ class DownloadClient(TorrentPath): self.client.prefs_init(prefs=prefs) try: self.client.add_category("BangumiCollection") - except Exception as e: + except Exception: logger.debug("[Downloader] Cannot add new category, maybe already exists.") if settings.downloader.path == "": prefs = self.client.get_app_prefs() @@ -109,7 +109,7 @@ class DownloadClient(TorrentPath): def delete_torrent(self, hashes): self.client.torrents_delete(hashes) - logger.info(f"[Downloader] Remove torrents.") + logger.info("[Downloader] Remove torrents.") def add_torrent(self, torrent: dict): if self.client.torrents_add( diff --git a/backend/src/module/manager/collector.py b/backend/src/module/manager/collector.py index 2ff955a0..30cd6a5f 100644 --- a/backend/src/module/manager/collector.py +++ b/backend/src/module/manager/collector.py @@ -1,7 +1,5 @@ import logging -from fastapi.responses import JSONResponse - from module.database import BangumiDatabase from module.downloader import DownloadClient from module.models import BangumiData diff --git a/backend/src/module/network/request_url.py b/backend/src/module/network/request_url.py index 51730f66..cc876f97 100644 --- a/backend/src/module/network/request_url.py +++ b/backend/src/module/network/request_url.py @@ -64,7 +64,7 @@ class RequestURL: req = requests.head(url=url, headers=self.header, timeout=5) req.raise_for_status() return True - except requests.RequestException as e: + except requests.RequestException: logger.debug(f"[Network] Cannot connect to {url}.") return False diff --git a/backend/src/module/notification/notification.py b/backend/src/module/notification/notification.py index 72d93a5b..e2262909 100644 --- a/backend/src/module/notification/notification.py +++ b/backend/src/module/notification/notification.py @@ -4,7 +4,12 @@ from module.conf import settings from module.database import BangumiDatabase from module.models import Notification -from .plugin import * +from .plugin import ( + BarkNotification, + ServerChanNotification, + TelegramNotification, + WecomNotification, +) logger = logging.getLogger(__name__) @@ -26,8 +31,7 @@ class PostNotification: def __init__(self): Notifier = getClient(settings.notification.type) self.notifier = Notifier( - token=settings.notification.token, - chat_id=settings.notification.chat_id + token=settings.notification.token, chat_id=settings.notification.chat_id ) @staticmethod @@ -37,11 +41,11 @@ class PostNotification: if poster_path: poster_link = "https://mikanani.me" + poster_path text = f""" - 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{poster_link}\n + 番剧名称:{notify.official_title}\n季度:第{notify.season}季\n更新集数:第{notify.episode}集\n{poster_link}\n """ else: text = f""" - 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n + 番剧名称:{notify.official_title}\n季度:第{notify.season}季\n更新集数:第{notify.episode}集\n """ return text @@ -61,6 +65,7 @@ class PostNotification: def __exit__(self, exc_type, exc_val, exc_tb): self.notifier.__exit__(exc_type, exc_val, exc_tb) + if __name__ == "__main__": info = Notification( official_title="魔法纪录 魔法少女小圆外传", diff --git a/backend/src/module/rss/poller.py b/backend/src/module/rss/poller.py index 9893d3be..00fa9c63 100644 --- a/backend/src/module/rss/poller.py +++ b/backend/src/module/rss/poller.py @@ -1,6 +1,5 @@ import re -from module.conf import settings from module.database import RSSDatabase from module.models import BangumiData, RSSTorrents from module.network import RequestContent, TorrentInfo @@ -25,4 +24,4 @@ class RSSPoller(RSSDatabase): rss_datas: list[RSSTorrents] = self.get_rss_data() with RequestContent() as req: for rss_data in rss_datas: - torrents = self.polling(rss_data.url, req) + self.polling(rss_data.url, req) diff --git a/backend/src/module/utils/bangumi_data.py b/backend/src/module/utils/bangumi_data.py index aeda2a3d..eea436a3 100644 --- a/backend/src/module/utils/bangumi_data.py +++ b/backend/src/module/utils/bangumi_data.py @@ -1,5 +1,3 @@ import logging -from .json_config import load, save - logger = logging.getLogger(__name__)