{"record":{"id":"7868cd71f5c5ca65","repo":"sansan0/TrendRadar","slug":"mode-daily-current","errorCode":null,"errorMessage":"不支持的模式: {mode}。支持的模式: daily, current","messagePattern":"不支持的模式: (.+?)。支持的模式: daily, current","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mcp_server/services/data_service.py","lineNumber":375,"sourceCode":"        if cached:\n            return cached\n\n        # 读取今天的数据\n        all_titles, id_to_name, timestamps = self.parser.read_all_titles_for_date()\n\n        if not all_titles:\n            raise DataNotFoundError(\n                \"未找到今天的新闻数据\",\n                suggestion=\"请确保爬虫已经运行并生成了数据\"\n            )\n\n        # 根据 mode 选择要处理的标题数据\n        if mode == \"daily\":\n            titles_to_process = all_titles\n        elif mode == \"current\":\n            titles_to_process = all_titles  # 简化实现\n        else:\n            raise ValueError(f\"不支持的模式: {mode}。支持的模式: daily, current\")\n\n        # 统计词频\n        word_frequency = Counter()\n        keyword_to_news = {}\n\n        # 预加载关键词数据（避免在循环内重复调用）\n        if extract_mode == \"keywords\":\n            from trendradar.core.frequency import _word_matches\n            word_groups = self.parser.parse_frequency_words()\n\n        # 遍历要处理的标题\n        for platform_id, titles in titles_to_process.items():\n            for title in titles.keys():\n                if extract_mode == \"keywords\":\n                    # 基于预设关键词统计（支持正则匹配）\n                    title_lower = title.lower()\n\n                    for group in word_groups:","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/services/data_service.py#L357-L393","documentation":"RSSParser.__init__ raises ImportError when the optional dependency feedparser was not importable at module load (guarded by the HAS_FEEDPARSER flag from the try/except import at the top of parser.py). The class is constructed eagerly even though parsing of RSS/Atom requires feedparser; JSON Feed parsing does not. This is a missing-optional-dependency error, not a code bug.","triggerScenarios":"Instantiating RSSParser() in an environment where 'import feedparser' failed: trendradar installed without the rss extra (pip install trendradar vs pip install trendradar[rss]), a venv mismatch where the package was installed into a different interpreter, or a broken/partial feedparser install.","commonSituations":"Deploying to a slim Docker image or CI runner without the RSS extras; activating the wrong virtualenv/conda env; a requirements.txt that omits feedparser because it is optional; upgrading Python versions and losing site-packages.","solutions":["Install the dependency: pip install feedparser (or reinstall trendradar with its rss extra, e.g. pip install 'trendradar[rss]' if defined).","Confirm you are in the same interpreter you installed into: 'python -c \"import feedparser\"' with the exact python/pip pair (python -m pip install feedparser avoids pip/interpreter mismatch).","Add feedparser to your deployment's requirements/lockfile so image builds include it.","If RSS features are intentionally unused, guard construction: only build RSSParser when RSS monitoring is enabled in config."],"exampleFix":"# before\nparser = RSSParser()  # ImportError in envs without feedparser\n\n# after\ntry:\n    parser = RSSParser()\nexcept ImportError:\n    logger.warning(\"RSS disabled: feedparser not installed (pip install feedparser)\")\n    parser = None\n\n# or simply, in shell:\n# pip install feedparser","handlingStrategy":"validation","validationCode":"from trendradar.crawler.rss import parser as rss_parser_mod\n\ndef rss_available() -> bool:\n    return rss_parser_mod.HAS_FEEDPARSER\n\nif not rss_available():\n    logger.warning(\"RSS features disabled; pip install feedparser\")","typeGuard":"from trendradar.crawler.rss.parser import RSSParser\n\ndef can_use_rss() -> bool:\n    \"\"\"Cheap check: feedparser importable == RSSParser constructible.\"\"\"\n    try:\n        import feedparser  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    parser = RSSParser()\nexcept ImportError as e:\n    logger.error(\"RSS disabled: %s\", e)\n    parser = None\n# gate all later use: if parser is None: skip rss jobs","preventionTips":["Pin feedparser in requirements/lockfile, not just as an optional extra, when RSS monitoring is part of your deployment.","Use python -m pip install so the dependency lands in the interpreter you run.","Fail fast at startup (probe imports for enabled features) rather than at first RSS job."],"tags":["rss","optional-dependency","import","environment"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}