archivebox_remove.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox remove'
  4. import sys
  5. import argparse
  6. from pathlib import Path
  7. from typing import Optional, List, IO
  8. from archivebox.misc.util import docstring
  9. from archivebox.config import DATA_DIR
  10. from ..logging_util import SmartFormatter, accept_stdin
  11. from ..main import remove
  12. @docstring(remove.__doc__)
  13. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  14. parser = argparse.ArgumentParser(
  15. prog=__command__,
  16. description=remove.__doc__,
  17. add_help=True,
  18. formatter_class=SmartFormatter,
  19. )
  20. parser.add_argument(
  21. '--yes', # '-y',
  22. action='store_true',
  23. help='Remove links instantly without prompting to confirm.',
  24. )
  25. parser.add_argument(
  26. '--delete', # '-r',
  27. action='store_true',
  28. help=(
  29. "In addition to removing the link from the index, "
  30. "also delete its archived content and metadata folder."
  31. ),
  32. )
  33. parser.add_argument(
  34. '--before', #'-b',
  35. type=float,
  36. help="List only URLs bookmarked before the given timestamp.",
  37. default=None,
  38. )
  39. parser.add_argument(
  40. '--after', #'-a',
  41. type=float,
  42. help="List only URLs bookmarked after the given timestamp.",
  43. default=None,
  44. )
  45. parser.add_argument(
  46. '--filter-type',
  47. type=str,
  48. choices=('exact', 'substring', 'domain', 'regex','tag'),
  49. default='exact',
  50. help='Type of pattern matching to use when filtering URLs',
  51. )
  52. parser.add_argument(
  53. 'filter_patterns',
  54. nargs='*',
  55. type=str,
  56. help='URLs matching this filter pattern will be removed from the index.'
  57. )
  58. command = parser.parse_args(args or ())
  59. filter_str = None
  60. if not command.filter_patterns:
  61. filter_str = accept_stdin(stdin)
  62. remove(
  63. filter_str=filter_str,
  64. filter_patterns=command.filter_patterns,
  65. filter_type=command.filter_type,
  66. before=command.before,
  67. after=command.after,
  68. yes=command.yes,
  69. delete=command.delete,
  70. out_dir=Path(pwd) if pwd else DATA_DIR,
  71. )
  72. if __name__ == '__main__':
  73. main(args=sys.argv[1:], stdin=sys.stdin)