From 93c3a77a57ad9645ec2d6418ee41a66a24b57d4e Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Mon, 6 Feb 2023 17:22:31 +0800 Subject: [PATCH] add counter --- nhentai/parser.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nhentai/parser.py b/nhentai/parser.py index 1d8d7a6..6bf007a 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -103,7 +103,7 @@ def favorites_parser(page=None): return result -def doujinshi_parser(id_): +def doujinshi_parser(id_, counter=0): if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()): raise Exception(f'Doujinshi id({id_}) is not valid') @@ -112,7 +112,6 @@ def doujinshi_parser(id_): doujinshi = dict() doujinshi['id'] = id_ url = f'{constant.DETAIL_URL}/{id_}/' - counter = 0 try: response = request('get', url) @@ -126,11 +125,11 @@ def doujinshi_parser(id_): if counter == 10: logger.critical(f'Failed to fetch doujinshi information of id {id_}') - sys.exit(1) + return None logger.debug(f'Slow down and retry ({id_}) ...') time.sleep(1) - return doujinshi_parser(str(id_)) + return doujinshi_parser(str(id_), counter) except Exception as e: logger.warning(f'Error: {e}, ignored')