403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.216
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/www/html/api.turmansolutions.ai/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/www/html/api.turmansolutions.ai//create_comments.py
"""
Comment Generation Script

Posts AI-generated comments on existing WordPress articles using characters from Drupal.

Usage:
    python create_comments.py <site_id> [options]

Options:
    --character <name>           Use only the specified character (bypass selection)
    --instructions-file <path>   Load custom instructions from file

Examples:
    python create_comments.py mysite
    python create_comments.py mysite --character "John Doe"
    python create_comments.py mysite --instructions-file prompts/supportive.txt
"""

import asyncio
import logging
import sys

# IMPORTANT: Import cron_common FIRST to load .env before any app imports
import cron_common

from app.api.agents.comments import Comments


# Parse comment arguments
site_id, character_name, user_instructions = cron_common.parse_comment_arguments(__doc__)

# Display configuration
print(f"site id: {site_id}")
if character_name:
    print(f"SINGLE CHARACTER MODE: {character_name}")
if user_instructions:
    print(f"Custom instructions loaded")

# Check internet connectivity
cron_common.check_internet_connectivity()

# Setup logging
cron_common.setup_logging('comments.log')

# Initialize services
wp_service, drupal_service, site_config_service, chat_service = cron_common.initialize_services()

# Load site configuration
site = cron_common.load_site_config(site_config_service, site_id)

# Get JWT token
wp_token = cron_common.get_jwt_token(wp_service, site, site_id)

# Fetch and filter characters
filtered_characters = cron_common.fetch_and_filter_characters(
    drupal_service, wp_service, site, site_id, wp_token
)

# Select characters for comment generation
characters = cron_common.select_characters(
    filtered_characters, drupal_service, site, character_name
)

# Filter out characters that already commented today (skip in single-character mode)
if not character_name:
    characters = cron_common.filter_already_commented_today(
        characters, wp_service, site, wp_token
    )

    if not characters:
        logging.info('No characters remaining after today-filter.')
        print('No characters remaining after today-filter.')
        sys.exit(0)

# Fetch all recent articles for comment generation (not filtered by author)
recent_articles = wp_service.get_recent_articles(site, wp_token, 100)

# Ensure recent_articles is not None
if recent_articles is None:
    recent_articles = []
    logging.warning("No recent articles returned, using empty list")

logging.info(f"Total recent articles: {len(recent_articles)}")

# Filter for articles with open comments
open_articles = [
    article for article in recent_articles if article["comment_status"] == "open"
]

logging.info(f"Total open articles: {len(open_articles)}")

# Load each character's existing articles (for context)
cron_common.load_character_articles(characters, wp_service, site, wp_token)

# Generate comments
if open_articles:
    comments_agent = Comments(site, wp_token)

    try:
        asyncio.run(comments_agent.run(characters, open_articles))
        logging.info(f"Successfully posted comments for {len(characters)} character(s)")
        print(f"Comment generation complete! Processed {len(open_articles)} open article(s)")
    except Exception as e:
        logging.error(f"Failed to post comments: {e}", exc_info=True)
        print(f"Error posting comments: {e}")
        sys.exit(1)
else:
    logging.info(f"No open articles found!")
    print("No open articles found for commenting.")

Youez - 2016 - github.com/yon3zu
LinuXploit