Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Python agent-infrastructureai-agentai-searchautomationbilibiliclaude-codeclicursorfree-apillm-toolsmcppythonreddit-scrapertwitter-scraperweb-scraperxiaohongshuyoutube-transcript
fix: improve error handling for Twitter Jina fallback and invalid URL inputs
Panniantonga5b7b93b1f55
diff --git a/agent_reach/channels/twitter.py b/agent_reach/channels/twitter.pyindex d54d5a09..d72d975c 100644--- a/agent_reach/channels/twitter.py+++ b/agent_reach/channels/twitter.py@@ -62,21 +62,56 @@ class TwitterChannel(Channel):)async def _read_jina(self, url: str) -> ReadResult:- resp = requests.get(- f"https://r.jina.ai/{url}",- headers={"Accept": "text/markdown"},- timeout=15,- )- resp.raise_for_status()- text = resp.text- title = text[:100] if text else url-- return ReadResult(- title=title,- content=text,- url=url,- platform="twitter",- )+ try:+ resp = requests.get(+ f"https://r.jina.ai/{url}",+ headers={"Accept": "text/markdown"},+ timeout=15,+ )+ resp.raise_for_status()+ text = resp.text++ # Detect unusable Jina responses for X/Twitter (JS-required pages)+ unusable_indicators = [+ "this page doesn't exist",+ "Don't miss what's happening",+ "Something went wrong. Try reloading",+ "Log in</a>",+ ]+ if any(indicator in text for indicator in unusable_indicators):+ return ReadResult(+ title="Twitter/X",+ content="⚠️ Could not read this tweet.\n"+ "The tweet may have been deleted, or the account is private.\n\n"+ "Tips:\n"+ "- Make sure the URL is correct\n"+ "- Try: birdx read <url> (if birdx is installed)\n"+ "- For protected tweets, configure Twitter cookies: "+ "agent-reach configure twitter-cookies AUTH_TOKEN CT0",+ url=url,+ platform="twitter",+ )++ title = text[:100] if text else url+ return ReadResult(+ title=title,+ content=text,+ url=url,+ platform="twitter",+ )+ except Exception:+ return ReadResult(+ title="Twitter/X",+ content="⚠️ Could not read this tweet.\n"+ "The tweet may have been deleted, or the account is private.\n\n"+ "Tips:\n"+ "- Make sure the URL is correct\n"+ "- Try: birdx read <url> (if birdx is installed)\n"+ "- For protected tweets, configure Twitter cookies: "+ "agent-reach configure twitter-cookies AUTH_TOKEN CT0",+ url=url,+ platform="twitter",+ )async def search(self, query: str, config=None, **kwargs) -> List[SearchResult]:limit = kwargs.get("limit", 10)diff --git a/agent_reach/cli.py b/agent_reach/cli.pyindex 356ebe0a..4d6ba2cc 100644--- a/agent_reach/cli.py+++ b/agent_reach/cli.py@@ -532,7 +532,15 @@ async def _cmd_read(args):print(f"👤 {result['author']}")print(f"\n{result.get('content', '')}")except Exception as e:- print(f"❌ Error: {e}", file=sys.stderr)+ error_str = str(e)+ if "400" in error_str and "Bad Request" in error_str:+ print(f"❌ Invalid URL: {args.url}", file=sys.stderr)+ print(" Please provide a valid URL (e.g., https://example.com)", file=sys.stderr)+ elif "ConnectionError" in type(e).__name__ or "Timeout" in type(e).__name__:+ print(f"❌ Could not connect to: {args.url}", file=sys.stderr)+ print(" Check your internet connection or the URL.", file=sys.stderr)+ else:+ print(f"❌ Error: {e}", file=sys.stderr)sys.exit(1)