This commit is contained in:
Mateusz Gruszczyński
2026-05-08 20:09:30 +02:00
parent 96e17d4b63
commit 02875fdc92
3 changed files with 51 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import sys
from .db import connect, init_db, utcnow
from .services.auth import password_hash
from .services import tracker_cache
def reset_password(username: str, password: str) -> bool:
@@ -30,6 +31,20 @@ def reset_password(username: str, password: str) -> bool:
return True
def fetch_tracker_favicon(domain: str, refresh: bool = True) -> str:
"""Note: Download or refresh one tracker favicon from CLI without starting the web server."""
clean = tracker_cache.tracker_domain(domain)
if not clean:
raise ValueError("Tracker domain is required")
init_db()
path, mime = tracker_cache.favicon_path(clean, enabled=True, force=refresh)
if not path:
row = tracker_cache.favicon_cache_row(clean)
detail = (row or {}).get("error") if row else "favicon not found"
raise RuntimeError(str(detail or "favicon not found"))
return f"{path} ({mime or 'unknown'})"
def _password_from_args(args: argparse.Namespace) -> str:
"""Note: Allow the password to be passed as an argument or entered securely in interactive mode."""
if args.password is not None:
@@ -51,6 +66,11 @@ def build_parser() -> argparse.ArgumentParser:
reset.add_argument("password", nargs="?", help="New password; omit to type it interactively")
reset.set_defaults(func=_cmd_reset_password)
icon = sub.add_parser("tracker-favicon", help="Download or refresh a tracker favicon cache file")
icon.add_argument("domain", help="Tracker domain, e.g. t.pte.nu")
icon.add_argument("--no-refresh", action="store_true", help="Use fresh cache when available")
icon.set_defaults(func=_cmd_tracker_favicon)
return parser
@@ -64,6 +84,12 @@ def _cmd_reset_password(args: argparse.Namespace) -> int:
return 1
def _cmd_tracker_favicon(args: argparse.Namespace) -> int:
"""Note: Run favicon discovery from CLI and print the saved file path."""
print(fetch_tracker_favicon(args.domain, refresh=not args.no_refresh))
return 0
def main(argv: list[str] | None = None) -> int:
"""Note: Main CLI entrypoint with error handling and without starting the web app."""
parser = build_parser()