INNER CODE UNIT · Python

get_safe_filename

zillionare/zillionare · scripts/enhanced_news_crawler.py:59

    def get_safe_filename(self, crawl_date: str) -> str:
        """生成安全的文件名"""
        # 使用slugify处理标题
        safe_title = slugify(self.title, max_length=100)
        if not safe_title:
            # 如果标题无法转换,使用URL的hash
            url_hash = hashlib.md5(self.url.encode()).hexdigest()[:8]
            safe_title = f"article_{url_hash}"

        return f"news/{crawl_date}/{safe_title}.md"


class EnhancedNewsCrawler:
    """增强版新闻爬虫"""

    def __init__(self, config_path: str = "rss.yaml"):
        self.config_path = config_path
        self.config = self._load_config()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…