mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-05-12 11:06:44 +08:00
fix: fix network bug, add log type
This commit is contained in:
@@ -34,6 +34,7 @@ class TorrentInfo:
|
||||
self.__fetch_mikan_info()
|
||||
return self._official_title
|
||||
|
||||
|
||||
class RequestContent(RequestURL):
|
||||
# Mikanani RSS
|
||||
def get_torrents(
|
||||
@@ -42,16 +43,19 @@ class RequestContent(RequestURL):
|
||||
_filter: str = "|".join(settings.rss_parser.filter),
|
||||
retry: int = 3,
|
||||
) -> [TorrentInfo]:
|
||||
soup = self.get_xml(_url, retry)
|
||||
torrent_titles, torrent_urls, torrent_homepage = mikan_parser(soup)
|
||||
try:
|
||||
soup = self.get_xml(_url, retry)
|
||||
torrent_titles, torrent_urls, torrent_homepage = mikan_parser(soup)
|
||||
|
||||
torrents = []
|
||||
for _title, torrent_url, homepage in zip(
|
||||
torrent_titles, torrent_urls, torrent_homepage
|
||||
):
|
||||
if re.search(_filter, _title) is None:
|
||||
torrents.append(TorrentInfo(name=_title, torrent_link=torrent_url, homepage=homepage))
|
||||
return torrents
|
||||
torrents = []
|
||||
for _title, torrent_url, homepage in zip(
|
||||
torrent_titles, torrent_urls, torrent_homepage
|
||||
):
|
||||
if re.search(_filter, _title) is None:
|
||||
torrents.append(TorrentInfo(name=_title, torrent_link=torrent_url, homepage=homepage))
|
||||
return torrents
|
||||
except ConnectionError:
|
||||
return []
|
||||
|
||||
def get_mikan_info(self, _url) -> tuple[str, str]:
|
||||
content = self.get_html(_url)
|
||||
|
||||
@@ -21,19 +21,18 @@ class RequestURL:
|
||||
req = self.session.get(url=url, headers=self.header, timeout=5)
|
||||
req.raise_for_status()
|
||||
return req
|
||||
except requests.RequestException as e:
|
||||
logger.debug(f"URL: {url}")
|
||||
logger.debug(e)
|
||||
logger.warning(f"Cannot connect to {url}. Wait for 5 seconds.")
|
||||
logger.warning("Please check DNS/Connection settings")
|
||||
except requests.RequestException:
|
||||
logger.warning(f"[Network] Cannot connect to {url}. Wait for 5 seconds.")
|
||||
try_time += 1
|
||||
if try_time >= retry:
|
||||
break
|
||||
time.sleep(5)
|
||||
except Exception as e:
|
||||
logger.debug(f"URL: {url}")
|
||||
logger.debug(e)
|
||||
break
|
||||
logger.error(f"[Network] Failed connecting to {url}")
|
||||
logger.warning("[Network] Please check DNS/Connection settings")
|
||||
raise ConnectionError(f"Failed connecting to {url}")
|
||||
|
||||
def post_url(self, url: str, data: dict, retry=3):
|
||||
try_time = 0
|
||||
@@ -44,18 +43,18 @@ class RequestURL:
|
||||
)
|
||||
req.raise_for_status()
|
||||
return req
|
||||
except requests.RequestException as e:
|
||||
logger.debug(e)
|
||||
logger.warning(f"Cannot connect to {url}.")
|
||||
logger.warning("Please check DNS/Connection settings")
|
||||
except requests.RequestException:
|
||||
logger.warning(f"[Network] Cannot connect to {url}. Wait for 5 seconds.")
|
||||
try_time += 1
|
||||
if try_time >= retry:
|
||||
break
|
||||
time.sleep(5)
|
||||
except Exception as e:
|
||||
logger.debug(f"URL: {url}")
|
||||
logger.debug(e)
|
||||
break
|
||||
logger.error(f"[Network] Failed connecting to {url}")
|
||||
logger.warning("[Network] Please check DNS/Connection settings")
|
||||
raise ConnectionError(f"Failed connecting to {url}")
|
||||
|
||||
def check_url(self, url: str):
|
||||
if "://" not in url:
|
||||
|
||||
Reference in New Issue
Block a user