From 0a7b6a6b7830392a2ee46d9cc2aea04ebe2ce8ac Mon Sep 17 00:00:00 2001 From: jackwener Date: Sun, 8 Mar 2026 22:37:00 +0800 Subject: [PATCH] fix: console output to stderr for clean --json output - Change Console() to Console(stderr=True) so all status/progress messages go to stderr, keeping stdout pure JSON when --json is used - Add missing exception handling in likes command for fetch_user - Fix SKILL.md: favorite -> favorites (correct command name) --- SKILL.md | 4 ++-- twitter_cli/cli.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/SKILL.md b/SKILL.md index 37ad1da..b8bbe21 100644 --- a/SKILL.md +++ b/SKILL.md @@ -32,7 +32,7 @@ twitter feed twitter feed -t following # Bookmarks -twitter favorite +twitter favorites # User profile and posts twitter user @@ -55,7 +55,7 @@ Filtering is opt-in (disabled by default). Enable with `--filter`. ```bash twitter feed --filter -twitter favorite --filter +twitter favorites --filter ``` The scoring formula: diff --git a/twitter_cli/cli.py b/twitter_cli/cli.py index 81830e9..e697aa2 100644 --- a/twitter_cli/cli.py +++ b/twitter_cli/cli.py @@ -46,7 +46,7 @@ from .formatter import ( from .serialization import tweets_from_json, tweets_to_json, users_to_json -console = Console() +console = Console(stderr=True) FEED_TYPES = ["for-you", "following"] @@ -296,7 +296,11 @@ def likes(screen_name, max_count, as_json, do_filter): config = load_config() client = _get_client(config) console.print("👤 Fetching @%s's profile..." % screen_name) - profile = client.fetch_user(screen_name) + try: + profile = client.fetch_user(screen_name) + except RuntimeError as exc: + console.print("[red]❌ %s[/red]" % exc) + sys.exit(1) _fetch_and_display( lambda count: client.fetch_user_likes(profile.id, count), "@%s likes" % screen_name, "❤️", max_count, as_json, None, do_filter, config,