shell_welcome_message.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 archivebox.cli import * # noqa
  21. CONFIG = archivebox.pm.hook.get_FLAT_CONFIG()
  22. if __name__ == '__main__':
  23. # load the rich extension for ipython for pretty printing
  24. # https://rich.readthedocs.io/en/stable/introduction.html#ipython-extension
  25. get_ipython().run_line_magic('load_ext', 'rich') # type: ignore # noqa
  26. # prnt = print with cropping using ... ellipsis for helptext that doens't matter that much
  27. console = Console()
  28. prnt = lambda *args, **kwargs: console.print(*args, overflow='ellipsis', soft_wrap=True, **kwargs)
  29. # print the welcome message
  30. prnt('[green]import re, os, sys, psutil, subprocess, reqiests, json, pydantic, benedict, django, abx[/]')
  31. prnt('[yellow4]# ArchiveBox Imports[/]')
  32. prnt('[yellow4]import archivebox[/]')
  33. prnt('[yellow4]from archivebox.cli import *[/]')
  34. prnt()
  35. if console.width >= 80:
  36. from archivebox.misc.logging import rainbow
  37. prnt(rainbow(archivebox.ASCII_LOGO))
  38. prnt('[i] :heavy_dollar_sign: Welcome to the ArchiveBox Shell!')
  39. 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]')
  40. prnt(' [link=https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html]https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html[/link]')
  41. prnt()
  42. prnt(' :grey_question: [violet]Hint[/] [i]Here are some examples to get started:[/]')
  43. prnt(' add[blink][deep_sky_blue4]?[/deep_sky_blue4][/blink] [grey53]# add ? after anything to get help[/]')
  44. prnt(' add("https://example.com/some/new/url") [grey53]# call CLI methods from the shell[/]')
  45. prnt(' snap = Snapshot.objects.filter(url__contains="https://example.com").last() [grey53]# query for individual snapshots[/]')
  46. prnt(' snap.archiveresult_set.all() [grey53]# see extractor results[/]')
  47. prnt(' bool(re.compile(CONFIG.URL_DENYLIST).search("https://example.com/abc.exe")) [grey53]# test out a config change[/]')