shell_welcome_message.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. __package__ = 'archivebox.core'
  2. from rich.console import Console
  3. # helpful imports that make the shell easier to work with out-of-the-box:
  4. import re # noqa
  5. import os # noqa
  6. import sys # noqa
  7. import json # noqa
  8. import psutil # noqa
  9. import django # noqa
  10. import pydantic # noqa
  11. import requests # noqa
  12. import subprocess # noqa
  13. import archivebox # noqa
  14. import abx # noqa
  15. from benedict import benedict # noqa
  16. from django.utils import timezone # noqa
  17. from datetime import datetime, timedelta # noqa
  18. from django.conf import settings # noqa
  19. from archivebox import CONSTANTS # noqa
  20. from ..main import * # noqa
  21. from ..cli import CLI_SUBCOMMANDS
  22. CONFIG = settings.FLAT_CONFIG
  23. CLI_COMMAND_NAMES = ", ".join(CLI_SUBCOMMANDS.keys())
  24. if __name__ == '__main__':
  25. # load the rich extension for ipython for pretty printing
  26. # https://rich.readthedocs.io/en/stable/introduction.html#ipython-extension
  27. get_ipython().run_line_magic('load_ext', 'rich') # type: ignore # noqa
  28. # prnt = print with cropping using ... ellipsis for helptext that doens't matter that much
  29. console = Console()
  30. prnt = lambda *args, **kwargs: console.print(*args, overflow='ellipsis', soft_wrap=True, **kwargs)
  31. # print the welcome message
  32. prnt('[green]import re, os, sys, psutil, subprocess, reqiests, json, pydantic, benedict, django, abx[/]')
  33. prnt('[yellow4]# ArchiveBox Imports[/]')
  34. prnt('[yellow4]import archivebox[/]')
  35. prnt('[yellow4]from archivebox.main import {}[/]'.format(CLI_COMMAND_NAMES))
  36. prnt()
  37. if console.width >= 80:
  38. from archivebox.misc.logging import rainbow
  39. prnt(rainbow(archivebox.ASCII_LOGO))
  40. prnt('[i] :heavy_dollar_sign: Welcome to the ArchiveBox Shell!')
  41. prnt(' [deep_sky_blue4]Docs:[/deep_sky_blue4] [link=https://github.com/ArchiveBox/ArchiveBox/wiki/Usage#Shell-Usage]https://github.com/ArchiveBox/ArchiveBox/wiki/Usage#Shell-Usage[/link]')
  42. prnt(' [link=https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html]https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html[/link]')
  43. prnt()
  44. prnt(' :grey_question: [violet]Hint[/] [i]Here are some examples to get started:[/]')
  45. prnt(' add[blink][deep_sky_blue4]?[/deep_sky_blue4][/blink] [grey53]# add ? after anything to get help[/]')
  46. prnt(' add("https://example.com/some/new/url") [grey53]# call CLI methods from the shell[/]')
  47. prnt(' snap = Snapshot.objects.filter(url__contains="https://example.com").last() [grey53]# query for individual snapshots[/]')
  48. prnt(' archivebox.plugins_extractor.wget.apps.WGET_EXTRACTOR.extract(snap.id) [grey53]# call an extractor directly[/]')
  49. prnt(' snap.archiveresult_set.all() [grey53]# see extractor results[/]')
  50. prnt(' bool(re.compile(CONFIG.URL_DENYLIST).search("https://example.com/abc.exe")) [grey53]# test out a config change[/]')