ArchiveBox/archivebox/misc/shell_welcome_message.py
2026-05-28 05:50:28 -07:00

65 lines
2.8 KiB
Python

__package__ = "archivebox.core"
from rich.console import Console
# helpful imports that make the shell easier to work with out-of-the-box:
import re # noqa
import os # noqa
import sys # noqa
import json # noqa
import psutil # noqa
import django # noqa
import pydantic # noqa
import requests # noqa
import subprocess # noqa
import archivebox
from django.utils import timezone # noqa
from datetime import datetime, timedelta # noqa
from archivebox import CONSTANTS # noqa
from archivebox.cli import * # noqa
from archivebox.config.common import get_config
from archivebox.misc.logging import AttrDict # noqa
if __name__ == "__main__":
CONFIG = get_config()
# load the rich extension for ipython for pretty printing
# https://rich.readthedocs.io/en/stable/introduction.html#ipython-extension
get_ipython().run_line_magic("load_ext", "rich") # type: ignore # noqa
# prnt = print with cropping using ... ellipsis for helptext that doesn't matter that much
console = Console()
prnt = lambda *args, **kwargs: console.print(*args, overflow="ellipsis", soft_wrap=True, **kwargs)
# print the welcome message
prnt("[green]import re, os, sys, psutil, subprocess, requests, json, pydantic, django[/]")
prnt("[yellow4]# ArchiveBox Imports[/]")
prnt("[yellow4]import archivebox[/]")
prnt("[yellow4]from archivebox.cli import *[/]")
prnt("[yellow4]from archivebox.misc.logging import AttrDict[/]")
prnt()
if console.width >= 80:
from archivebox.misc.logging import rainbow
prnt(rainbow(archivebox.ASCII_LOGO))
prnt("[i] :heavy_dollar_sign: Welcome to the ArchiveBox Shell!")
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]",
)
prnt(
" [link=https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html]https://docs.archivebox.io/en/dev/apidocs/archivebox/archivebox.html[/link]",
)
prnt()
prnt(" :grey_question: [violet]Hint[/] [i]Here are some examples to get started:[/]")
prnt(
" add[blink][deep_sky_blue4]?[/deep_sky_blue4][/blink] [grey53]# add ? after anything to get help[/]",
)
prnt(' add("https://example.com/some/new/url") [grey53]# call CLI methods from the shell[/]')
prnt(' snap = Snapshot.objects.filter(url__contains="https://example.com").last() [grey53]# query for individual snapshots[/]')
prnt(" snap.archiveresult_set.all() [grey53]# see extractor plugin results[/]")
prnt(' bool(re.compile(CONFIG.URL_DENYLIST).search("https://example.com/abc.exe")) [grey53]# test out a config change[/]')