From 4e8266b305084f7cf4206d220d832fa9af38e71b Mon Sep 17 00:00:00 2001 From: beare <945412026@qq.com> Date: Tue, 5 May 2026 01:50:38 +0800 Subject: [PATCH] refactor: simplify sorting logic in get_high_score_news function - Updated the sorting mechanism in the get_high_score_news function to directly use the 'score' key, enhancing code readability and performance. --- src/opennews_mcp/tools/news.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/opennews_mcp/tools/news.py b/src/opennews_mcp/tools/news.py index d1de67a..61cfad5 100644 --- a/src/opennews_mcp/tools/news.py +++ b/src/opennews_mcp/tools/news.py @@ -231,10 +231,7 @@ async def get_high_score_news(ctx: Context, min_score: int = 70, limit: int = 10 try: result = await api.search_news(score=min_score, limit=limit, page=1) data = result.get("data", []) - data.sort( - key=lambda x: (x.get("aiRating") or {}).get("score", 0), - reverse=True, - ) + data.sort(key=lambda x: x.get("score", 0), reverse=True) return make_serializable({ "success": True, "min_score": min_score, "data": data[:limit], "count": len(data[:limit]), "total": result.get("total", 0),