load EXTRACTORS dynamically using importlib.import_module

This commit is contained in:
Nick Sweeting 2024-05-11 22:28:59 -07:00
parent c7f55fc3ba
commit 457c42bf84
No known key found for this signature in database
18 changed files with 198 additions and 40 deletions

View file

@ -19,13 +19,17 @@ from ..config import (
from ..logging_util import TimedProgress
def get_output_path():
return 'output.pdf'
@enforce_types
def should_save_pdf(link: Link, out_dir: Optional[Path]=None, overwrite: Optional[bool]=False) -> bool:
if is_static_file(link.url):
return False
out_dir = out_dir or Path(link.link_dir)
if not overwrite and (out_dir / 'output.pdf').exists():
if not overwrite and (out_dir / get_output_path()).exists():
return False
return SAVE_PDF
@ -36,7 +40,7 @@ def save_pdf(link: Link, out_dir: Optional[Path]=None, timeout: int=TIMEOUT) ->
"""print PDF of site to file using chrome --headless"""
out_dir = out_dir or Path(link.link_dir)
output: ArchiveOutput = 'output.pdf'
output: ArchiveOutput = get_output_path()
cmd = [
*chrome_args(),
'--print-to-pdf',
@ -51,7 +55,7 @@ def save_pdf(link: Link, out_dir: Optional[Path]=None, timeout: int=TIMEOUT) ->
hints = (result.stderr or result.stdout).decode()
raise ArchiveError('Failed to save PDF', hints)
chmod_file('output.pdf', cwd=str(out_dir))
chmod_file(get_output_path(), cwd=str(out_dir))
except Exception as err:
status = 'failed'
output = err