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(xueqiu): honor and clamp hot-post limits
Osamaali31331b028f4fc93
diff --git a/agent_reach/channels/xueqiu.py b/agent_reach/channels/xueqiu.pyindex 0fc752d7..1ecf45b5 100644--- a/agent_reach/channels/xueqiu.py+++ b/agent_reach/channels/xueqiu.py@@ -235,9 +235,14 @@ class XueqiuChannel(Channel):Returns a list of dicts with keys:id, title, text, author, likes, url"""+ if limit < 0:+ raise ValueError("limit must be non-negative")+ limit = min(limit, 50)+ if limit == 0:+ return []data = _get_json("https://xueqiu.com/v4/statuses/public_timeline_by_category.json"- "?since_id=-1&max_id=-1&count=20&category=-1"+ f"?since_id=-1&max_id=-1&count={limit}&category=-1")items = data.get("list") or []results = []diff --git a/tests/test_xueqiu_channel.py b/tests/test_xueqiu_channel.pyindex 9b8fda66..4b1ace2b 100644--- a/tests/test_xueqiu_channel.py+++ b/tests/test_xueqiu_channel.py@@ -13,6 +13,9 @@ import jsonimport sysimport typesfrom unittest.mock import patch+from urllib.parse import parse_qs, urlsplit++import pytestfrom agent_reach.channels import xueqiu as xqfrom agent_reach.channels.xueqiu import XueqiuChannel, _strip_html@@ -211,6 +214,52 @@ def test_get_hot_posts_tolerates_bad_data_field():assert p["url"] == ""+def test_get_hot_posts_requests_the_requested_count():+ ch = XueqiuChannel()+ captured = {}++ def fake_get_json(url):+ captured["url"] = url+ return {"list": []}++ with patch.object(xq, "_get_json", side_effect=fake_get_json):+ ch.get_hot_posts(limit=50)++ assert parse_qs(urlsplit(captured["url"]).query)["count"] == ["50"]+++def test_get_hot_posts_clamps_count_to_documented_maximum():+ ch = XueqiuChannel()+ captured = {}+ payload = {"list": [{"data": "{}"}] * 60}++ def fake_get_json(url):+ captured["url"] = url+ return payload++ with patch.object(xq, "_get_json", side_effect=fake_get_json):+ posts = ch.get_hot_posts(limit=500)++ assert parse_qs(urlsplit(captured["url"]).query)["count"] == ["50"]+ assert len(posts) == 50+++def test_get_hot_posts_zero_limit_skips_network():+ ch = XueqiuChannel()+ with patch.object(+ xq,+ "_get_json",+ side_effect=AssertionError("zero limit must not make a request"),+ ):+ assert ch.get_hot_posts(limit=0) == []+++def test_get_hot_posts_rejects_negative_limit():+ ch = XueqiuChannel()+ with pytest.raises(ValueError, match="non-negative"):+ ch.get_hot_posts(limit=-1)++# --- get_hot_stocks: ranking + code/symbol fallback ---def test_get_hot_stocks_ranks_and_falls_back_to_symbol():