| 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.johnturman.net/__pycache__/ |
Upload File : |
o
�Dj�H � @ sX d Z ddlZddlmZ ddlmZ ddlZddlZddlm Z m
Z
mZ ddlm
Z
ee�jd Ze
ed� dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZmZmZ d4de e deee e eeeeeee e e e e e e e e e ef fdd�Z d4de e deee e ef fdd�Z!d5dd�Z"deddfdd�Z#deeeeef fdd�Z$dededefdd�Z%ded ededefd!d"�Z&d#eded eded$ede
e fd%d&�Z' 'd6d(e
e d#ed ed)e e d*ede
e fd+d,�Z(d-e
e ded ed$eddf
d.d/�Z)d-e
e ded ed$ede
e f
d0d1�Z*d-e
e ded ed$ede
e f
d2d3�Z+dS )7z�
Common utilities and setup functions for cron scripts.
This module provides shared functionality for article and comment generation scripts,
reducing code duplication and ensuring consistent behavior.
� N)�RotatingFileHandler)�Path)�Optional�List�Tuple)�load_dotenvz.env)Zdotenv_path)� WpService)�
DrupalService)�SiteConfigService)�ChatService)� Character�
SiteConfig�WpUser� help_text�returnc C s� t tj�dk r| rt| � ntd� t�d� tjd }d}dtjv rCtj�d�}|d t tj�k r:tj|d }n td� t�d� d}dtjv r�tj�d�}|d t tj�k r�tj|d }z&t|d d
d��}|�� �� }W d � n1 syw Y td|� �� W n; t y� td
|� �� t�d� Y n' t
y� } ztd|� �� t�d� W Y d}~nd}~ww td� t�d� dtjv }dtjv } dtjv }
dtjv }dtjv }dtjv}
d}dtjv �rtj�d�}|d t tj�k r�tj|d }n td� t�d� d}dtjv �r?tj�d�}|d t tj�k �r6tj|d }|dv�r5td� t�d� n td� t�d� d}dtjv �r�tj�d�}|d t tj�k �r�zttj|d �}|dk �sk|dk�rttd� t�d� W n t�y� td� t�d� Y n
w td � t�d� d}d!tjv �r�tj�d!�}|d t tj�k �r�tj|d }n td"� t�d� d}d#tjv �r�tj�d#�}|d t tj�k �r�tj|d }n td$� t�d� d%tjv �rftj�d%�}|d t tj�k �r]tj|d }z't|d d
d��}|�� �� }W d � n 1 �sw Y td&|� �� W n= t �y> td'|� �� t�d� Y n( t
�y\ } ztd(|� �� t�d� W Y d}~nd}~ww td)� t�d� ||||| |
||
||||||fS )*a0
Parse command-line arguments for article creation.
Args:
help_text: Help text to display when no arguments provided (typically __doc__)
Returns:
Tuple of (site_id, character_name, character_description_override,
generate_featured_image, generate_secondary_image,
run_fact_check, research_current_events, include_previous_articles,
series_name, search_depth_override, chunks_per_source_override,
seed_image_url, seed_image_instructions, run_corrections)
� z4Usage: python create_articles.py <site_id> [options]� N�--character�,Error: --character requires a character name� z--character-description-file�r�utf-8��encodingz,Loaded character description override from: z-Error: Character description file not found: z*Error reading character description file: z8Error: --character-description-file requires a file pathz--featured-imagez--secondary-imagez--fact-checkz
--correctionsz--current-eventsz--no-previous-articlesz--seriesz&Error: --series requires a series namez--search-depth)ZbasicZadvancedz3Error: --search-depth must be 'basic' or 'advanced'z:Error: --search-depth requires a value (basic or advanced)z--chunks-per-source� z2Error: --chunks-per-source must be between 1 and 3z4Error: --chunks-per-source requires an integer valuez1Error: --chunks-per-source requires a value (1-3)z--seed-image-urlz&Error: --seed-image-url requires a URLz--seed-image-instructionsz2Error: --seed-image-instructions requires a stringz--seed-image-instructions-filez%Loaded seed image instructions from: z/Error: Seed image instructions file not found: z,Error reading seed image instructions file: z:Error: --seed-image-instructions-file requires a file path)
�len�sys�argv�print�exit�index�open�read�strip�FileNotFoundError� Exception�int�
ValueError)r �site_id�character_name�idxZcharacter_description_overrideZdescription_file�f�eZgenerate_featured_imageZgenerate_secondary_imageZrun_fact_checkZrun_correctionsZresearch_current_eventsZinclude_previous_articlesZseries_nameZsearch_depth_overrideZchunks_per_source_overrideZseed_image_urlZseed_image_instructionsZseed_instructions_file� r- �/tsai/repo/api/cron_common.py�parse_article_arguments s�
���
�
��
���
�r/ c
C s� t tj�dk r| rt| � ntd� t�d� tjd }d}dtjv rCtj�d�}|d t tj�k r:tj|d }n td� t�d� d}dtjv r�tj�d�}|d t tj�k r�tj|d }z&t|d d
d��}|�� �� }W d � n1 syw Y td|� �� W n; t y� td
|� �� t�d� Y n' t
y� } ztd|� �� t�d� W Y d}~nd}~ww td� t�d� |||fS )z�
Parse command-line arguments for comment creation.
Args:
help_text: Help text to display when no arguments provided (typically __doc__)
Returns:
Tuple of (site_id, character_name, user_instructions)
r z4Usage: python create_comments.py <site_id> [options]r Nr r r z--instructions-filer r r zLoaded instructions from: z$Error: Instructions file not found: z!Error reading instructions file: z/Error: --instructions-file requires a file path)r r r r r r r! r"