"""Keyword research knowledge loader."""
import json
from typing import Any
from ..config import KNOWLEDGE_DIR
def get_keyword_research() -> dict[str, Any]:
"""Load keyword research data from knowledge files.
Returns:
Dictionary containing keyword research including:
- categories: Grouped keyword lists
- category_name: Name of the category
- keywords: List of keywords with metadata
- keyword: The keyword/phrase
- search_volume: Monthly search volume
- competition: low/medium/high
- suggested_bid: Suggested CPC
- intent: informational/navigational/transactional
- negative_keywords: Keywords to exclude
- brand_keywords: Brand-related terms
If no keyword file exists, returns a template structure.
"""
keywords_file = KNOWLEDGE_DIR / "keywords.json"
if keywords_file.exists():
with open(keywords_file, "r", encoding="utf-8") as f:
return json.load(f)
# Return template structure if no file exists
return {
"categories": [
{
"category_name": "Example Category",
"keywords": [
{
"keyword": "example keyword",
"search_volume": 0,
"competition": "medium",
"suggested_bid": 0.0,
"intent": "transactional",
}
],
}
],
"negative_keywords": [],
"brand_keywords": [],
"_note": "This is a template. Create data/knowledge/keywords.json with your actual keyword research.",
}
def save_keyword_research(keywords: dict[str, Any]) -> None:
"""Save keyword research to the knowledge file.
Args:
keywords: The keywords dictionary to save.
"""
KNOWLEDGE_DIR.mkdir(parents=True, exist_ok=True)
keywords_file = KNOWLEDGE_DIR / "keywords.json"
with open(keywords_file, "w", encoding="utf-8") as f:
json.dump(keywords, f, indent=2)