cli.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. # vim: tabstop=4 shiftwidth=4 expandtab
  3. import argparse
  4. from pathlib import Path
  5. from gemini_antenna.db import AntennaDB
  6. argparser = argparse.ArgumentParser(
  7. description="CLI tool to manage Antenna",
  8. epilog="Call '%(prog)s refresh --help' to see subcommand options."
  9. )
  10. subparsers = argparser.add_subparsers(
  11. dest="command", required=True, help="sub-command help"
  12. )
  13. parser_refresh = subparsers.add_parser(
  14. "refresh", help="check feeds for new updates"
  15. )
  16. parser_refresh.add_argument(
  17. "-f", "--force", action="store_true", help="Run even if queue is empty."
  18. )
  19. parser_refresh.add_argument(
  20. "-F", "--feedpage",
  21. help="File to output generated RSS/Atom/gemsub feed text/gemini to. "
  22. "Defaults to stdout."
  23. )
  24. parser_refresh.add_argument(
  25. "-A", "--atomfeedpage",
  26. help="File to output generated RSS/Atom/gemsub feed Atom XML to. "
  27. "Defaults to stdout."
  28. )
  29. parser_refresh.add_argument(
  30. "-T", "--twtxtpage",
  31. help="File to output generated twtxt text/gemini to. "
  32. "Defaults to stdout."
  33. )
  34. parser_refresh.add_argument(
  35. "-t", "--twtxtfile",
  36. help="File to output generated twtxt text/plain to. Defaults to stdout."
  37. )
  38. parser_refresh.add_argument(
  39. "-S", "--statfile", default=None,
  40. help="File to output feed statistics to. Defaults to stdout."
  41. )
  42. parser_refresh.add_argument(
  43. "-q", "--silent", action="store_true",
  44. help="Do not output. This overrides '--feedpage/--atomfeedpage/--twtxtpage/"
  45. "--twtxtfile/--statfile'."
  46. )
  47. parser_list = subparsers.add_parser("list", help="list all URLs in the table")
  48. parser_delete = subparsers.add_parser(
  49. "delete", help="delete all the given URLs from the table"
  50. )
  51. parser_delete.add_argument("URLs", nargs="+")
  52. parser_add = subparsers.add_parser(
  53. "add", help="bulk addition of feeds to queue"
  54. )
  55. parser_add.add_argument("URLs", nargs="+")
  56. argparser.add_argument(
  57. "-d", "--dataroot", type=Path, default=Path.cwd(),
  58. help="Set the data directory where Antenna will store its files. "
  59. "Defaults to the current directory."
  60. )
  61. def main():
  62. args = argparser.parse_args()
  63. if args.command == "refresh":
  64. import gemini_antenna.ingestfeeds
  65. gemini_antenna.ingestfeeds.actionRefresh(args)
  66. return
  67. db = AntennaDB(args.dataroot / "antenna.sqlite")
  68. if args.command == "list":
  69. print('\n'.join(db.getQueue()))
  70. elif args.command == "delete":
  71. db.deleteFromQueue(*args.URLs)
  72. elif args.command == "add":
  73. db.queueFeed(*args.URLs)
  74. if __name__ == "__main__":
  75. main()