Skip to content

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

fix: Reddit 子版块列表页支持 + --version 参数

Panniantong3efc8d1d5599
diff --git a/agent_reach/channels/reddit.py b/agent_reach/channels/reddit.py
index 174006a6..30bbfbf8 100644
--- a/agent_reach/channels/reddit.py
+++ b/agent_reach/channels/reddit.py
@@ -74,6 +74,10 @@ class RedditChannel(Channel):
data = resp.json()
+ # Subreddit listing page: /r/sub/, /r/sub/hot, /r/sub/new, /r/sub/top
+ if isinstance(data, dict) and data.get("kind") == "Listing":
+ return self._parse_listing(data, url)
+
if isinstance(data, list) and len(data) >= 1:
# Post page: [post_listing, comments_listing]
post = data[0]["data"]["children"][0]["data"]
@@ -103,6 +107,52 @@ class RedditChannel(Channel):
raise ValueError(f"Could not parse Reddit response for: {url}")
+ def _parse_listing(self, data: dict, url: str) -> ReadResult:
+ """Parse a subreddit listing (hot/new/top/rising)."""
+ children = data.get("data", {}).get("children", [])
+
+ # Extract subreddit name and sort from URL
+ parsed = urlparse(url)
+ path_parts = [p for p in parsed.path.strip("/").split("/") if p]
+ subreddit = path_parts[1] if len(path_parts) >= 2 else "reddit"
+ sort_type = path_parts[2] if len(path_parts) >= 3 else "hot"
+
+ lines = []
+ for i, child in enumerate(children, 1):
+ if child.get("kind") != "t3":
+ continue
+ post = child.get("data", {})
+ title = post.get("title", "")
+ author = post.get("author", "")
+ score = post.get("score", 0)
+ num_comments = post.get("num_comments", 0)
+ permalink = post.get("permalink", "")
+ post_url = post.get("url", "")
+ is_self = post.get("is_self", False)
+
+ lines.append(f"### {i}. {title}")
+ lines.append(f"👤 u/{author} · ⬆ {score} · 💬 {num_comments}")
+ if not is_self and post_url:
+ lines.append(f"🔗 {post_url}")
+ lines.append(f"📎 https://www.reddit.com{permalink}")
+ # Add selftext preview (first 200 chars)
+ selftext = post.get("selftext", "")
+ if selftext:
+ preview = selftext[:200].replace("\n", " ")
+ if len(selftext) > 200:
+ preview += "..."
+ lines.append(f"> {preview}")
+ lines.append("")
+
+ content = "\n".join(lines) if lines else "No posts found."
+ return ReadResult(
+ title=f"r/{subreddit} — {sort_type}",
+ content=content,
+ url=url,
+ platform="reddit",
+ extra={"subreddit": subreddit, "sort": sort_type, "count": len(children)},
+ )
+
def _extract_comments(self, comments_data: dict, depth: int = 0, max_depth: int = 3) -> str:
"""Recursively extract comments."""
lines = []
diff --git a/agent_reach/cli.py b/agent_reach/cli.py
index 4d6ba2cc..3ed51057 100644
--- a/agent_reach/cli.py
+++ b/agent_reach/cli.py
@@ -36,6 +36,7 @@ def main():
description="👁️ Give your AI Agent eyes to see the entire internet",
)
parser.add_argument("-v", "--verbose", action="store_true", help="Show debug logs")
+ parser.add_argument("--version", action="version", version=f"Agent Reach v{__version__}")
sub = parser.add_subparsers(dest="command", help="Available commands")
# ── read ──