Skip to content

Commit

Permalink
Moved search args to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
YofaGh committed Aug 7, 2024
1 parent a0ff63d commit 427d502
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __call__(self, parser, namespace, values, option_string=None):
settings.AUTO_MERGE = args.m or settings.AUTO_MERGE
settings.AUTO_PDF_CONVERSION = args.p or settings.AUTO_PDF_CONVERSION
settings.FIT_MERGE = args.fit or settings.FIT_MERGE
settings.SEARCH_PAGE_LIMIT = args.page_limit or settings.SEARCH_PAGE_LIMIT
settings.SEARCH_ABSOLUTE = args.absolute or settings.SEARCH_ABSOLUTE

if args.task in ('manga', 'doujin', 'search', 'db') and not args.file:
from utils.modules_contributer import get_modules
Expand Down Expand Up @@ -107,7 +109,7 @@ def __call__(self, parser, namespace, values, option_string=None):
if not args.n:
parser.error('you should specify what you want to search using -n')
from crawlers.search_engine import search_wrapper
search_wrapper(args.n, args.s, args.absolute, args.page_limit)
search_wrapper(args.n, args.s)

case 'db':
from crawlers.database_crawler import crawl
Expand Down
13 changes: 7 additions & 6 deletions crawlers/search_engine.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from utils.logger import log_over, log
from utils.assets import save_json_file, sleep
from utils.exceptions import MissingFunctionException
from settings import SEARCH_PAGE_LIMIT, SEARCH_ABSOLUTE

def search_wrapper(keyword, modules, absolute, limit_page):
def search_wrapper(keyword, modules):
results = {}
for module in modules:
try:
temp_results = search(keyword, module, absolute, limit_page)
temp_results = search(keyword, module)
if temp_results:
results[module.domain] = temp_results
except MissingFunctionException as error:
Expand All @@ -15,20 +16,20 @@ def search_wrapper(keyword, modules, absolute, limit_page):
print_output(results)
log(f'This was a summary of the search.\nYou can see the full results in {keyword}_output.json', 'green')

def search(keyword, module, absolute, limit_page):
def search(keyword, module):
if not hasattr(module, 'search_by_keyword'):
raise MissingFunctionException(module.domain, 'search_by_keyword')
search = module.search_by_keyword(keyword, absolute)
search = module.search_by_keyword(keyword, SEARCH_ABSOLUTE)
results, page = {}, 1
while page <= limit_page:
while page <= SEARCH_PAGE_LIMIT:
try:
log_over(f'\r{module.domain}: Searching page {page}...')
last = next(search)
if not last:
break
results.update(last)
page += 1
if page < limit_page:
if page < SEARCH_PAGE_LIMIT:
sleep()
except Exception as error:
log(f'\r{module.domain}: Failed to search: {error}', 'red')
Expand Down
2 changes: 2 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
AUTO_MERGE = False
AUTO_PDF_CONVERSION = False
FIT_MERGE = False
SEARCH_PAGE_LIMIT = 3
SEARCH_ABSOLUTE = False
MODULES_FILE_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'modules.yaml')

0 comments on commit 427d502

Please sign in to comment.