From f9878d080b06a34f1adcc57734b36671ed95f2d7 Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Sat, 4 Mar 2023 18:49:28 +0800 Subject: [PATCH] add debug information --- nhentai/cmdline.py | 2 +- nhentai/constant.py | 1 + nhentai/parser.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 4bd4f47..31db53a 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -79,7 +79,7 @@ def cmd_parser(): help='all search results') parser.add_option('--page', '--page-range', type='string', dest='page', action='store', default='', help='page number of search results. e.g. 1,2-5,14') - parser.add_option('--sorting', dest='sorting', action='store', default='popular', + parser.add_option('--sorting', '--sort', dest='sorting', action='store', default='popular', help='sorting of doujinshi (recent / popular / popular-[today|week])', choices=['recent', 'popular', 'popular-today', 'popular-week', 'date']) diff --git a/nhentai/constant.py b/nhentai/constant.py index c5c9092..eb80b5e 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -5,6 +5,7 @@ import tempfile from urllib.parse import urlparse +DEBUG = os.getenv('DEBUG', False) BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net') DETAIL_URL = f'{BASE_URL}/g' diff --git a/nhentai/parser.py b/nhentai/parser.py index 988ba80..8d6bf3f 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -292,12 +292,19 @@ def search_parser(keyword, sorting, page, is_page_all=False): try: url = request('get', url=constant.SEARCH_URL, params={'query': keyword, 'page': p, 'sort': sorting}).url + + if constant.DEBUG: + logger.debug(f'Request URL: {url}?query={keyword}&page={p}&sort={sorting}') + response = request('get', url.replace('%2B', '+')).json() except Exception as e: logger.critical(str(e)) response = None break + if constant.DEBUG: + logger.debug(f'Response: {response}') + if response is None or 'result' not in response: logger.warning(f'No result in response in page {p}') if not_exists_persist is True: