1
0
Fork 0

fix: Remove title from extractors for oneshot

This commit is contained in:
Cristian 2020-07-31 10:24:58 -05:00
parent 8bcb171e74
commit e6c571beb2
4 changed files with 37 additions and 14 deletions

View file

@ -32,22 +32,32 @@ from .git import should_save_git, save_git
from .media import should_save_media, save_media from .media import should_save_media, save_media
from .archive_org import should_save_archive_dot_org, save_archive_dot_org from .archive_org import should_save_archive_dot_org, save_archive_dot_org
def get_default_archive_methods():
return [
('title', should_save_title, save_title),
('favicon', should_save_favicon, save_favicon),
('wget', should_save_wget, save_wget),
('pdf', should_save_pdf, save_pdf),
('screenshot', should_save_screenshot, save_screenshot),
('dom', should_save_dom, save_dom),
('git', should_save_git, save_git),
('media', should_save_media, save_media),
('archive_org', should_save_archive_dot_org, save_archive_dot_org),
]
@enforce_types
def ignore_methods(to_ignore: List[str]):
ARCHIVE_METHODS = get_default_archive_methods()
methods = filter(lambda x: x[0] not in to_ignore, ARCHIVE_METHODS)
methods = map(lambda x: x[1], methods)
return list(methods)
@enforce_types @enforce_types
def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[str]]=None, out_dir: Optional[str]=None, skip_index: bool=False) -> Link: def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[str]]=None, out_dir: Optional[str]=None, skip_index: bool=False) -> Link:
"""download the DOM, PDF, and a screenshot into a folder named after the link's timestamp""" """download the DOM, PDF, and a screenshot into a folder named after the link's timestamp"""
ARCHIVE_METHODS = [ ARCHIVE_METHODS = get_default_archive_methods()
('title', should_save_title, save_title),
('favicon', should_save_favicon, save_favicon),
('wget', should_save_wget, save_wget),
('pdf', should_save_pdf, save_pdf),
('screenshot', should_save_screenshot, save_screenshot),
('dom', should_save_dom, save_dom),
('git', should_save_git, save_git),
('media', should_save_media, save_media),
('archive_org', should_save_archive_dot_org, save_archive_dot_org),
]
if methods is not None: if methods is not None:
ARCHIVE_METHODS = [ ARCHIVE_METHODS = [
method for method in ARCHIVE_METHODS method for method in ARCHIVE_METHODS

View file

@ -52,7 +52,7 @@ from .index.sql import (
remove_from_sql_main_index, remove_from_sql_main_index,
) )
from .index.html import parse_html_main_index from .index.html import parse_html_main_index
from .extractors import archive_links, archive_link from .extractors import archive_links, archive_link, ignore_methods
from .config import ( from .config import (
stderr, stderr,
ConfigDict, ConfigDict,
@ -503,7 +503,8 @@ def oneshot(url: str, out_dir: str=OUTPUT_DIR):
color='red' color='red'
) )
raise SystemExit(2) raise SystemExit(2)
archive_link(oneshot_link[0], out_dir=out_dir, skip_index=True) methods = ignore_methods(['title'])
archive_link(oneshot_link[0], out_dir=out_dir, methods=methods, skip_index=True)
return oneshot_link return oneshot_link
@enforce_types @enforce_types

View file

@ -1,5 +1,13 @@
from .fixtures import * from .fixtures import *
from archivebox.extractors import ignore_methods, get_default_archive_methods, should_save_title
def test_wget_broken_pipe(tmp_path, process): def test_wget_broken_pipe(tmp_path, process):
add_process = subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/example.com.html'], capture_output=True) add_process = subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/example.com.html'], capture_output=True)
assert "TypeError chmod_file(..., path: str) got unexpected NoneType argument path=None" not in add_process.stdout.decode("utf-8") assert "TypeError chmod_file(..., path: str) got unexpected NoneType argument path=None" not in add_process.stdout.decode("utf-8")
def test_ignore_methods():
"""
Takes the passed method out of the default methods list and returns that value
"""
ignored = ignore_methods(['title'])
assert should_save_title not in ignored

View file

@ -1,3 +1,5 @@
from pathlib import Path
from .fixtures import * from .fixtures import *
def test_oneshot_command_exists(tmp_path): def test_oneshot_command_exists(tmp_path):
@ -8,5 +10,7 @@ def test_oneshot_command_exists(tmp_path):
def test_oneshot_commad_saves_page_in_right_folder(tmp_path): def test_oneshot_commad_saves_page_in_right_folder(tmp_path):
process = subprocess.run(["archivebox", "oneshot", f"--out-dir={tmp_path}", "http://127.0.0.1:8080/static/example.com.html"], capture_output=True) process = subprocess.run(["archivebox", "oneshot", f"--out-dir={tmp_path}", "http://127.0.0.1:8080/static/example.com.html"], capture_output=True)
items = ' '.join([str(x) for x in tmp_path.iterdir()]) items = ' '.join([str(x) for x in tmp_path.iterdir()])
current_path = ' '.join([str(x) for x in Path.cwd().iterdir()])
assert "index.json" in items assert "index.json" in items
assert not "index.sqlite3" in current_path