diff --git a/pynyaata/bridge/animeultime.py b/pynyaata/bridge/animeultime.py index 2183a50..19484e5 100644 --- a/pynyaata/bridge/animeultime.py +++ b/pynyaata/bridge/animeultime.py @@ -2,12 +2,12 @@ from datetime import datetime, timedelta from typing import List from bs4 import BeautifulSoup -import dateparser +from dateparser import parse from pydantic import HttpUrl, parse_obj_as from pynyaata.cache import cache_data from pynyaata.filters import filter_data -from pynyaata.types import Bridge, Color, RemoteFile +from pynyaata.types import Bridge, Color, RemoteFile, log_async import requests @@ -33,6 +33,7 @@ class AnimeUltime(Bridge): ), ) + @log_async @cache_data @filter_data async def search(self, query: str = "", page: int = 1) -> List[RemoteFile]: @@ -87,9 +88,7 @@ class AnimeUltime(Bridge): category=tds[4].get_text(), name=tds[0].get_text(), link=f"{self.base_url}{tds[0].a['href']}", - date=dateparser.parse( - h3s[i].get_text()[:-3], ["%A %d %B %Y"] - ), + date=parse(h3s[i].get_text()[:-3], ["%A %d %B %Y"]), ) ) elif player and title and history and tables: diff --git a/pynyaata/bridge/nyaa.py b/pynyaata/bridge/nyaa.py index 1b7707c..caf27cf 100644 --- a/pynyaata/bridge/nyaa.py +++ b/pynyaata/bridge/nyaa.py @@ -8,7 +8,7 @@ from pydantic import HttpUrl, parse_obj_as from pynyaata.cache import cache_data from pynyaata.filters import filter_data -from pynyaata.types import Bridge, Color, RemoteFile +from pynyaata.types import Bridge, Color, RemoteFile, log_async import requests @@ -37,6 +37,7 @@ class Nyaa(Bridge): return parse_obj_as(HttpUrl, f"{self.base_url}?{params}") + @log_async @cache_data @filter_data async def search(self, query: str = "", page: int = 1) -> List[RemoteFile]: diff --git a/pynyaata/bridge/yggtorrent.py b/pynyaata/bridge/yggtorrent.py index b322c68..e250bad 100644 --- a/pynyaata/bridge/yggtorrent.py +++ b/pynyaata/bridge/yggtorrent.py @@ -7,7 +7,7 @@ from pydantic import HttpUrl, parse_obj_as from pynyaata.cache import cache_data from pynyaata.filters import filter_data from pynyaata.session import FlareRequests -from pynyaata.types import Bridge, Color, RemoteFile +from pynyaata.types import Bridge, Color, RemoteFile, log_async from requests import HTTPError @@ -32,6 +32,7 @@ class YggTorrent(Bridge): return parse_obj_as(HttpUrl, f"{self.base_url}?{params}") + @log_async @cache_data @filter_data async def search(self, query: str = "", page: int = 1) -> List[RemoteFile]: diff --git a/pynyaata/cache/__init__.py b/pynyaata/cache/__init__.py index b902898..20b74b8 100644 --- a/pynyaata/cache/__init__.py +++ b/pynyaata/cache/__init__.py @@ -1,5 +1,5 @@ -import logging from functools import wraps +from logging import error from os import getenv from typing import Optional @@ -19,12 +19,12 @@ if REDIS_URL: client = RedisCache() except RedisError as e: - logging.error(e) + error(e) def cache_data(f): @wraps(f) - async def wrapper(*args, **kwds): + async def wrapper(*args, **kwargs): bridge = args[0] query = args[1] page = args[2] @@ -34,7 +34,7 @@ def cache_data(f): if ret: return ret - ret = await f(*args, **kwds) + ret = await f(*args, **kwargs) client.set(key, ret) return ret diff --git a/pynyaata/filters.py b/pynyaata/filters.py index 147a1b9..141b5a9 100644 --- a/pynyaata/filters.py +++ b/pynyaata/filters.py @@ -50,8 +50,8 @@ def danger(remotes: List[RemoteFile]) -> List[RemoteFile]: def filter_data(f): @wraps(f) - async def wrapper(*args, **kwds): - ret = await f(*args, **kwds) + async def wrapper(*args, **kwargs): + ret = await f(*args, **kwargs) ret = duplicate(ret) ret = inactive(ret) diff --git a/pynyaata/types.py b/pynyaata/types.py index 6b06bfb..6fc6eaf 100644 --- a/pynyaata/types.py +++ b/pynyaata/types.py @@ -1,6 +1,8 @@ from abc import ABC, abstractmethod from datetime import datetime from enum import Enum +from functools import wraps +from logging import error from typing import List, Optional from pydantic import BaseModel, ByteSize, HttpUrl @@ -62,3 +64,15 @@ class Cache(ABC): @abstractmethod def set(self, key: str, data: List[RemoteFile]): pass + + +def log_async(f): + @wraps(f) + async def wrapper(*args, **kwargs): + try: + return await f(*args, **kwargs) + except Exception as e: + error(e) + raise e + + return wrapper