Skip to main content
Glama
funinii

TrendRadar

by funinii

get_news_by_date

Retrieve news data from multiple platforms for a specific date to support historical analysis and comparison of trending topics.

Instructions

获取指定日期的新闻数据,用于历史数据分析和对比

Args: date_query: 日期查询,可选格式: - 自然语言: "今天", "昨天", "前天", "3天前" - 标准日期: "2024-01-15", "2024/01/15" - 默认值: "今天"(节省token) platforms: 平台ID列表,如 ['zhihu', 'weibo', 'douyin'] - 不指定时:使用 config.yaml 中配置的所有平台 - 支持的平台来自 config/config.yaml 的 platforms 配置 - 每个平台都有对应的name字段(如"知乎"、"微博"),方便AI识别 limit: 返回条数限制,默认50,最大1000 注意:实际返回数量可能少于请求值,取决于指定日期的新闻总数 include_url: 是否包含URL链接,默认False(节省token)

Returns: JSON格式的新闻列表,包含标题、平台、排名等信息

重要:数据展示建议 本工具会返回完整的新闻列表(通常50条)给你。但请注意:

  • 工具返回:完整的50条数据 ✅

  • 建议展示:向用户展示全部数据,除非用户明确要求总结

  • 用户期望:用户可能需要完整数据,请谨慎总结

何时可以总结

  • 用户明确说"给我总结一下"或"挑重点说"

  • 数据量超过100条时,可先展示部分并询问是否查看全部

注意:如果用户询问"为什么只显示了部分",说明他们需要完整数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
date_queryNo
platformsNo
limitNo
include_urlNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Tool handler for get_news_by_date in DataQueryTools class.
    def get_news_by_date(
        self,
        date_query: Optional[str] = None,
        platforms: Optional[List[str]] = None,
        limit: Optional[int] = None,
        include_url: bool = False
    ) -> Dict:
        """
        按日期查询新闻,支持自然语言日期
    
        Args:
            date_query: 日期查询字符串(可选,默认"今天"),支持:
                - 相对日期:今天、昨天、前天、3天前、yesterday、3 days ago
                - 星期:上周一、本周三、last monday、this friday
                - 绝对日期:2025-10-10、10月10日、2025年10月10日
            platforms: 平台ID列表,如 ['zhihu', 'weibo']
            limit: 返回条数限制,默认50
            include_url: 是否包含URL链接,默认False(节省token)
    
        Returns:
            新闻列表字典
    
        Example:
            >>> tools = DataQueryTools()
            >>> # 不指定日期,默认查询今天
            >>> result = tools.get_news_by_date(platforms=['zhihu'], limit=20)
            >>> # 指定日期
            >>> result = tools.get_news_by_date(
            ...     date_query="昨天",
            ...     platforms=['zhihu'],
            ...     limit=20
            ... )
            >>> print(result['total'])
            20
        """
        try:
            # 参数验证 - 默认今天
            if date_query is None:
                date_query = "今天"
            target_date = validate_date_query(date_query)
            platforms = validate_platforms(platforms)
            limit = validate_limit(limit, default=50)
    
            # 获取数据
            news_list = self.data_service.get_news_by_date(
                target_date=target_date,
                platforms=platforms,
                limit=limit,
                include_url=include_url
            )
    
            return {
                "news": news_list,
                "total": len(news_list),
                "date": target_date.strftime("%Y-%m-%d"),
                "date_query": date_query,
                "platforms": platforms,
                "success": True
            }
    
        except MCPError as e:
            return {
                "success": False,
                "error": e.to_dict()
            }
        except Exception as e:
            return {
                "success": False,
                "error": {
                    "code": "INTERNAL_ERROR",
                    "message": str(e)
                }
            }
  • Implementation of get_news_by_date in DataService class which performs the actual data retrieval.
    def get_news_by_date(
        self,
        target_date: datetime,
        platforms: Optional[List[str]] = None,
        limit: int = 50,
        include_url: bool = False
    ) -> List[Dict]:
        """
        按指定日期获取新闻
    
        Args:
            target_date: 目标日期
            platforms: 平台ID列表,None表示所有平台
            limit: 返回条数限制
            include_url: 是否包含URL链接,默认False(节省token)
    
        Returns:
            新闻列表
    
        Raises:
            DataNotFoundError: 数据不存在
    
        Examples:
            >>> service = DataService()
            >>> news = service.get_news_by_date(
            ...     target_date=datetime(2025, 10, 10),
            ...     platforms=['zhihu'],
            ...     limit=20
            ... )
        """
        # 尝试从缓存获取
        date_str = target_date.strftime("%Y-%m-%d")
        cache_key = f"news_by_date:{date_str}:{','.join(platforms or [])}:{limit}:{include_url}"
        cached = self.cache.get(cache_key, ttl=1800)  # 30分钟缓存
        if cached:
            return cached
    
        # 读取指定日期的数据
        all_titles, id_to_name, timestamps = self.parser.read_all_titles_for_date(
            date=target_date,
            platform_ids=platforms
        )
    
        # 转换为新闻列表
        news_list = []
        for platform_id, titles in all_titles.items():
            platform_name = id_to_name.get(platform_id, platform_id)
    
            for title, info in titles.items():
                # 计算平均排名
                avg_rank = sum(info["ranks"]) / len(info["ranks"]) if info["ranks"] else 0
    
                news_item = {
                    "title": title,
                    "platform": platform_id,
                    "platform_name": platform_name,
                    "rank": info["ranks"][0] if info["ranks"] else 0,
                    "avg_rank": round(avg_rank, 2),
                    "count": len(info["ranks"]),
                    "date": date_str
                }
    
                # 条件性添加 URL 字段
                if include_url:
                    news_item["url"] = info.get("url", "")
                    news_item["mobileUrl"] = info.get("mobileUrl", "")
    
                news_list.append(news_item)
    
        # 按排名排序
        news_list.sort(key=lambda x: x["rank"])
    
        # 限制返回数量
        result = news_list[:limit]
    
        # 缓存结果(历史数据缓存更久)
        self.cache.set(cache_key, result)
    
        return result
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the tool returns JSON-formatted news lists with titles, platforms, rankings, etc.; it may return fewer items than requested based on available data; and it includes important usage notes about data display and user expectations. However, it lacks details on error handling, rate limits, or authentication needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately front-loaded with the core purpose and parameter details, but it includes extensive additional sections on data display recommendations and user interaction scenarios. While these are useful, they extend the length and could be streamlined or moved to a separate guidelines section. Every sentence earns its place, but the structure could be more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters, no annotations, 0% schema coverage, but with an output schema), the description is highly complete. It covers the tool's purpose, detailed parameter semantics, return format, and extensive usage guidelines. The output schema likely handles return values, so the description appropriately focuses on other aspects, making it well-rounded for agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must fully compensate. It does so excellently by explaining all four parameters in detail: 'date_query' with format options and default; 'platforms' with examples, default behavior, and configuration source; 'limit' with default, max, and note on actual returns; and 'include_url' with default and rationale. This adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '获取指定日期的新闻数据,用于历史数据分析和对比' (Get news data for a specified date, for historical data analysis and comparison). It specifies the verb ('获取' - get) and resource ('新闻数据' - news data), and distinguishes it from siblings like 'get_latest_news' (which likely gets current news) by focusing on historical data by date.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidelines, including when to use this tool (for historical data analysis and comparison) and when not to (e.g., for current news, use 'get_latest_news' implicitly). It also offers detailed guidance on data presentation, such as showing full data unless the user requests a summary, and handling cases where users ask why only part of the data is shown.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/funinii/TrendRadar'

If you have feedback or need assistance with the MCP directory API, please join our Discord server