Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:666ghj BettaFish KeywordManager get all keywords

From Leeroopedia
Knowledge Sources
Domains Web_Crawling, Database
Last Updated 2026-10-08 00:00 GMT

Overview

Concrete manager class that retrieves crawl keywords from the database with a fallback chain: today's topics, recent 7 days, or default keywords.

Description

The KeywordManager class connects to the database and retrieves keywords for deep sentiment crawling. It implements a fallback chain: 1. Try to get keywords for the specified date from the `daily_topics` table 2. If no data for that date, try the most recent 7 days' keywords 3. If no recent data, return default platform-specific keywords

Keywords are deduplicated and randomly sampled if they exceed the max limit, ensuring variety across crawling runs.

Usage

Import this class when you need keywords for platform crawling. It runs before PlatformCrawler in the MindSpider DeepSentimentCrawling workflow.

Code Reference

Source Location

  • Repository: BettaFish
  • File: `MindSpider/DeepSentimentCrawling/keyword_manager.py:L29-335`

Signature

class KeywordManager:
    def __init__(self):
        """Initialize and connect to database."""

    def get_latest_keywords(
        self,
        target_date: date = None,
        max_keywords: int = 100
    ) -> List[str]:
        """Get keywords for a specific date, with fallback."""

    def get_all_keywords_for_platforms(
        self,
        platforms: List[str],
        target_date: date = None,
        max_keywords: int = 100
    ) -> List[str]:
        """
        Get keywords shared across all specified platforms.

        Args:
            platforms: Platform IDs (xhs, dy, ks, bili, wb, tieba, zhihu)
            target_date: Date for keyword lookup (default: today)
            max_keywords: Maximum keywords to return

        Returns:
            List[str] of keywords
        """

Import

from MindSpider.DeepSentimentCrawling.keyword_manager import KeywordManager

I/O Contract

Inputs

Name Type Required Description
platforms List[str] Yes Platform IDs (xhs, dy, ks, bili, wb, tieba, zhihu)
target_date date No Date for keyword lookup (default: today)
max_keywords int No Max keywords (default: 100)

Outputs

Name Type Description
keywords List[str] Keywords for crawling

Usage Examples

Get Keywords for Crawling

from MindSpider.DeepSentimentCrawling.keyword_manager import KeywordManager

mgr = KeywordManager()
keywords = mgr.get_all_keywords_for_platforms(
    platforms=["xhs", "dy", "wb", "bili"],
    max_keywords=50
)
print(f"Got {len(keywords)} keywords: {keywords[:10]}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment