72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
"""
|
|
Configuration module for WordPress SEO automation.
|
|
Loads and validates environment variables.
|
|
"""
|
|
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from pathlib import Path
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
class Config:
|
|
"""Configuration class for WordPress SEO automation."""
|
|
|
|
# WordPress Settings
|
|
WORDPRESS_URL = os.getenv('WORDPRESS_URL', '').rstrip('/')
|
|
WORDPRESS_USERNAME = os.getenv('WORDPRESS_USERNAME', '')
|
|
WORDPRESS_APP_PASSWORD = os.getenv('WORDPRESS_APP_PASSWORD', '')
|
|
|
|
# OpenRouter API Settings
|
|
OPENROUTER_API_KEY = os.getenv('OPENROUTER_API_KEY', '')
|
|
AI_MODEL = os.getenv('AI_MODEL', 'anthropic/claude-3.5-sonnet')
|
|
|
|
# Script Settings
|
|
BATCH_SIZE = int(os.getenv('BATCH_SIZE', '100'))
|
|
API_DELAY_SECONDS = float(os.getenv('API_DELAY_SECONDS', '0.5'))
|
|
|
|
# Analysis Settings
|
|
ANALYSIS_MIN_POSITION = int(os.getenv('ANALYSIS_MIN_POSITION', '11'))
|
|
ANALYSIS_MAX_POSITION = int(os.getenv('ANALYSIS_MAX_POSITION', '30'))
|
|
ANALYSIS_MIN_IMPRESSIONS = int(os.getenv('ANALYSIS_MIN_IMPRESSIONS', '50'))
|
|
ANALYSIS_TOP_N_POSTS = int(os.getenv('ANALYSIS_TOP_N_POSTS', '20'))
|
|
|
|
# Output directory
|
|
OUTPUT_DIR = Path(__file__).parent / 'output'
|
|
|
|
@classmethod
|
|
def validate(cls):
|
|
"""Validate that all required configuration is present."""
|
|
errors = []
|
|
|
|
if not cls.WORDPRESS_URL:
|
|
errors.append("WORDPRESS_URL is required")
|
|
|
|
if not cls.WORDPRESS_USERNAME:
|
|
errors.append("WORDPRESS_USERNAME is required")
|
|
|
|
if not cls.WORDPRESS_APP_PASSWORD:
|
|
errors.append("WORDPRESS_APP_PASSWORD is required")
|
|
|
|
if not cls.OPENROUTER_API_KEY:
|
|
errors.append("OPENROUTER_API_KEY is required (get one from https://openrouter.ai/)")
|
|
|
|
if errors:
|
|
raise ValueError("Configuration errors:\n" + "\n".join(f" - {e}" for e in errors))
|
|
|
|
# Create output directory if it doesn't exist
|
|
cls.OUTPUT_DIR.mkdir(exist_ok=True)
|
|
|
|
return True
|
|
|
|
@classmethod
|
|
def get_wordpress_auth(cls):
|
|
"""Get WordPress authentication tuple."""
|
|
return (cls.WORDPRESS_USERNAME, cls.WORDPRESS_APP_PASSWORD)
|
|
|
|
@classmethod
|
|
def get_api_base_url(cls):
|
|
"""Get WordPress REST API base URL."""
|
|
return f"{cls.WORDPRESS_URL}/wp-json/wp/v2"
|