MCPcopy
hub / github.com/sansan0/TrendRadar / compare_platforms

Method compare_platforms

mcp_server/tools/analytics.py:425–547  ·  view source on GitHub ↗

平台对比分析 - 对比不同平台对同一话题的关注度 Args: topic: 话题关键词(可选,不指定则对比整体活跃度) date_range: 日期范围,格式: {"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"} Returns: 平台对比分析结果 Examples: 用户询问示例: - "对比一下各个平台对'人工智能'话题的关注度" - "看

(
        self,
        topic: Optional[str] = None,
        date_range: Optional[Union[Dict[str, str], str]] = None
    )

Source from the content-addressed store, hash-verified

423 }
424
425 def compare_platforms(
426 self,
427 topic: Optional[str] = None,
428 date_range: Optional[Union[Dict[str, str], str]] = None
429 ) -> Dict:
430 """
431 平台对比分析 - 对比不同平台对同一话题的关注度
432
433 Args:
434 topic: 话题关键词(可选,不指定则对比整体活跃度)
435 date_range: 日期范围,格式: {"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"}
436
437 Returns:
438 平台对比分析结果
439
440 Examples:
441 用户询问示例:
442 - "对比一下各个平台对'人工智能'话题的关注度"
443 - "看看知乎和微博哪个平台更关注科技新闻"
444 - "分析各平台今天的热点分布"
445
446 代码调用示例:
447 >>> # 对比各平台(假设今天是 2025-11-17)
448 >>> result = tools.compare_platforms(
449 ... topic="人工智能",
450 ... date_range={"start": "2025-11-08", "end": "2025-11-17"}
451 ... )
452 >>> print(result['platform_stats'])
453 """
454 try:
455 # 参数验证
456 if topic:
457 topic = validate_keyword(topic)
458 date_range_tuple = validate_date_range(date_range)
459
460 # 确定日期范围
461 if date_range_tuple:
462 start_date, end_date = date_range_tuple
463 else:
464 start_date = end_date = datetime.now()
465
466 # 收集各平台数据
467 platform_stats = defaultdict(lambda: {
468 "total_news": 0,
469 "topic_mentions": 0,
470 "unique_titles": set(),
471 "top_keywords": Counter()
472 })
473
474 # 遍历日期范围
475 current_date = start_date
476 while current_date <= end_date:
477 try:
478 all_titles, id_to_name, _ = self.data_service.parser.read_all_titles_for_date(
479 date=current_date
480 )
481
482 for platform_id, titles in all_titles.items():

Callers 1

Calls 7

_extract_keywordsMethod · 0.95
_find_unique_topicsMethod · 0.95
validate_keywordFunction · 0.85
validate_date_rangeFunction · 0.85
getMethod · 0.80
to_dictMethod · 0.45

Tested by

no test coverage detected