Skip to content

Commit

Permalink
optimize logger output #390
Browse files Browse the repository at this point in the history
  • Loading branch information
RicterZ committed Feb 9, 2025
1 parent 023c896 commit 0a47527
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
17 changes: 10 additions & 7 deletions nhentai/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,25 @@ def cmd_parser():

# --- set config ---
if args.cookie is not None:
constant.CONFIG['cookie'] = args.cookie
constant.CONFIG['cookie'] = args.cookie.strip()
write_config()
logger.info('Cookie saved.')
sys.exit(0)
elif args.useragent is not None:
constant.CONFIG['useragent'] = args.useragent

if args.useragent is not None:
constant.CONFIG['useragent'] = args.useragent.strip()
write_config()
logger.info('User-Agent saved.')
sys.exit(0)
elif args.language is not None:

if args.language is not None:
constant.CONFIG['language'] = args.language
write_config()
logger.info(f'Default language now set to "{args.language}"')
sys.exit(0)
# TODO: search without language

if any([args.cookie, args.useragent, args.language]):
sys.exit(0)
# -- end set config

if args.proxy is not None:
proxy_url = urlparse(args.proxy)
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https', 'socks5', 'socks5h',
Expand Down
4 changes: 0 additions & 4 deletions nhentai/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import sys
import signal
import platform
import urllib

import urllib3.exceptions
from requests import options

from nhentai import constant
from nhentai.cmdline import cmd_parser, banner, write_config
Expand All @@ -16,7 +13,6 @@
from nhentai.downloader import Downloader
from nhentai.logger import logger
from nhentai.constant import BASE_URL
from nhentai.serializer import serialize_json
from nhentai.utils import generate_html, generate_doc, generate_main_html, generate_metadata_file, \
paging, check_cookie, signal_handler, DB, move_to_folder

Expand Down
9 changes: 5 additions & 4 deletions nhentai/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,24 @@ def favorites_parser(page=None):
logger.info(f'Getting doujinshi ids of page {page}')

i = 0
while i < constant.RETRY_TIMES:
if i == 2:
while i <= constant.RETRY_TIMES + 1:
i += 1
if i > 3:
logger.error(f'Failed to get favorites at page {page} after 3 times retried, skipped')
break

try:
resp = request('get', f'{constant.FAV_URL}?page={page}').content
temp_result = _get_title_and_id(resp)
if not temp_result:
i += 1
logger.warning(f'Failed to get favorites at page {page}, retrying ({i} times) ...')
continue
else:
result.extend(temp_result)
break

except Exception as e:
logger.warning(f'Error: {e}, retrying ({i} times)...')
logger.warning(f'Error: {e}, retrying ({i} times) ...')

return result

Expand Down

0 comments on commit 0a47527

Please sign in to comment.