mirror of
https://github.com/pirate/ArchiveBox.git
synced 2025-08-29 01:00:11 +02:00
allow passing links to remove method
This commit is contained in:
@@ -547,6 +547,7 @@ def add(urls: Union[str, List[str]],
|
|||||||
def remove(filter_str: Optional[str]=None,
|
def remove(filter_str: Optional[str]=None,
|
||||||
filter_patterns: Optional[List[str]]=None,
|
filter_patterns: Optional[List[str]]=None,
|
||||||
filter_type: str='exact',
|
filter_type: str='exact',
|
||||||
|
links: Optional[List[Link]]=None,
|
||||||
after: Optional[float]=None,
|
after: Optional[float]=None,
|
||||||
before: Optional[float]=None,
|
before: Optional[float]=None,
|
||||||
yes: bool=False,
|
yes: bool=False,
|
||||||
@@ -556,38 +557,40 @@ def remove(filter_str: Optional[str]=None,
|
|||||||
|
|
||||||
check_data_folder(out_dir=out_dir)
|
check_data_folder(out_dir=out_dir)
|
||||||
|
|
||||||
if filter_str and filter_patterns:
|
if links is None:
|
||||||
stderr(
|
if filter_str and filter_patterns:
|
||||||
'[X] You should pass either a pattern as an argument, '
|
stderr(
|
||||||
'or pass a list of patterns via stdin, but not both.\n',
|
'[X] You should pass either a pattern as an argument, '
|
||||||
color='red',
|
'or pass a list of patterns via stdin, but not both.\n',
|
||||||
)
|
color='red',
|
||||||
raise SystemExit(2)
|
)
|
||||||
elif not (filter_str or filter_patterns):
|
raise SystemExit(2)
|
||||||
stderr(
|
elif not (filter_str or filter_patterns):
|
||||||
'[X] You should pass either a pattern as an argument, '
|
stderr(
|
||||||
'or pass a list of patterns via stdin.',
|
'[X] You should pass either a pattern as an argument, '
|
||||||
color='red',
|
'or pass a list of patterns via stdin.',
|
||||||
)
|
color='red',
|
||||||
stderr()
|
)
|
||||||
stderr(' {lightred}Hint:{reset} To remove all urls you can run:'.format(**ANSI))
|
stderr()
|
||||||
stderr(" archivebox remove --filter-type=regex '.*'")
|
stderr(' {lightred}Hint:{reset} To remove all urls you can run:'.format(**ANSI))
|
||||||
stderr()
|
stderr(" archivebox remove --filter-type=regex '.*'")
|
||||||
raise SystemExit(2)
|
stderr()
|
||||||
elif filter_str:
|
raise SystemExit(2)
|
||||||
filter_patterns = [ptn.strip() for ptn in filter_str.split('\n')]
|
elif filter_str:
|
||||||
|
filter_patterns = [ptn.strip() for ptn in filter_str.split('\n')]
|
||||||
|
|
||||||
|
log_list_started(filter_patterns, filter_type)
|
||||||
|
timer = TimedProgress(360, prefix=' ')
|
||||||
|
try:
|
||||||
|
links = list(list_links(
|
||||||
|
filter_patterns=filter_patterns,
|
||||||
|
filter_type=filter_type,
|
||||||
|
after=after,
|
||||||
|
before=before,
|
||||||
|
))
|
||||||
|
finally:
|
||||||
|
timer.end()
|
||||||
|
|
||||||
log_list_started(filter_patterns, filter_type)
|
|
||||||
timer = TimedProgress(360, prefix=' ')
|
|
||||||
try:
|
|
||||||
links = list(list_links(
|
|
||||||
filter_patterns=filter_patterns,
|
|
||||||
filter_type=filter_type,
|
|
||||||
after=after,
|
|
||||||
before=before,
|
|
||||||
))
|
|
||||||
finally:
|
|
||||||
timer.end()
|
|
||||||
|
|
||||||
if not len(links):
|
if not len(links):
|
||||||
log_removal_finished(0, 0)
|
log_removal_finished(0, 0)
|
||||||
@@ -606,7 +609,8 @@ def remove(filter_str: Optional[str]=None,
|
|||||||
should_remove = (
|
should_remove = (
|
||||||
(after is not None and float(link.timestamp) < after)
|
(after is not None and float(link.timestamp) < after)
|
||||||
or (before is not None and float(link.timestamp) > before)
|
or (before is not None and float(link.timestamp) > before)
|
||||||
or link_matches_filter(link, filter_patterns, filter_type)
|
or link_matches_filter(link, filter_patterns or [], filter_type)
|
||||||
|
or link in links
|
||||||
)
|
)
|
||||||
if should_remove:
|
if should_remove:
|
||||||
to_delete.append(link)
|
to_delete.append(link)
|
||||||
|
Reference in New Issue
Block a user