From 1b499111667ea8f36c2b02ae3ad582c99494f62e Mon Sep 17 00:00:00 2001 From: RicterZ Date: Tue, 30 Jul 2019 23:03:29 +0800 Subject: [PATCH] code style --- nhentai/cmdline.py | 7 ++++--- nhentai/command.py | 4 ++-- nhentai/parser.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 475c662..f34e54e 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -48,7 +48,8 @@ def cmd_parser(): # doujinshi options parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3') - parser.add_option('--search', '-s', type='string', dest='keyword', action='store', help='search doujinshi by keyword') + parser.add_option('--search', '-s', type='string', dest='keyword', action='store', + help='search doujinshi by keyword') parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag') parser.add_option('--favorites', '-F', action='store_true', dest='favorites', help='list or download your favorites.') @@ -58,8 +59,8 @@ def cmd_parser(): help='page number of search results') parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1, help='The max page when recursive download tagged doujinshi') - parser.add_option('--sorting', type='string', dest='sorting', action='store', default='date', - help='sorting of doujinshi, e.g. date/popular') + parser.add_option('--sorting', dest='sorting', action='store', default='date', + help='sorting of doujinshi (date / popular)', choices=['date', 'popular']) # download options parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='', diff --git a/nhentai/command.py b/nhentai/command.py index 9d3cb68..7d7fbf0 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -40,13 +40,13 @@ def main(): doujinshi_ids = map(lambda d: d['id'], doujinshis) elif options.tag: - doujinshis = tag_parser(options.tag, options.sorting, max_page=options.max_page) + doujinshis = tag_parser(options.tag, sorting=options.sorting, max_page=options.max_page) print_doujinshi(doujinshis) if options.is_download and doujinshis: doujinshi_ids = map(lambda d: d['id'], doujinshis) elif options.keyword: - doujinshis = search_parser(options.keyword, options.sorting, options.page) + doujinshis = search_parser(options.keyword, sorting=options.sorting, page=options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) diff --git a/nhentai/parser.py b/nhentai/parser.py index b6a23e2..33130ec 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -169,7 +169,7 @@ def doujinshi_parser(id_): return doujinshi -def search_parser(keyword, sorting, page): +def search_parser(keyword, sorting='date', page=1): logger.debug('Searching doujinshis of keyword {0}'.format(keyword)) try: response = request('get', url=constant.SEARCH_URL, params={'q': keyword, 'page': page, 'sort': sorting}).content @@ -194,7 +194,7 @@ def print_doujinshi(doujinshi_list): tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) -def tag_parser(tag_name, sorting, max_page=1): +def tag_parser(tag_name, sorting='date', max_page=1): result = [] tag_name = tag_name.lower() tag_name = tag_name.replace(' ', '-')