|
|
|
@ -9,8 +9,7 @@ mkdir -p "$LOG_DIR" "$LOCK_DIR" || { echo "Error: Failed to create $LOG_DIR or $ |
|
|
|
# Handle stop command |
|
|
|
# Handle stop command |
|
|
|
if [ "$1" == "stop" ]; then |
|
|
|
if [ "$1" == "stop" ]; then |
|
|
|
log "Received stop command, stopping all scripts..." |
|
|
|
log "Received stop command, stopping all scripts..." |
|
|
|
stop_scripts # Stop foodie_automator_*.py scripts (includes lock file removal) |
|
|
|
stop_scripts |
|
|
|
# Stop foodie_engagement_generator.py |
|
|
|
|
|
|
|
if pkill -TERM -f "$VENV_PYTHON.*foodie_engagement_generator"; then |
|
|
|
if pkill -TERM -f "$VENV_PYTHON.*foodie_engagement_generator"; then |
|
|
|
log "Sent TERM to foodie_engagement_generator.py" |
|
|
|
log "Sent TERM to foodie_engagement_generator.py" |
|
|
|
sleep 2 |
|
|
|
sleep 2 |
|
|
|
@ -20,7 +19,6 @@ if [ "$1" == "stop" ]; then |
|
|
|
fi |
|
|
|
fi |
|
|
|
rm -f "$LOCK_DIR/foodie_engagement_generator.lock" || log "Failed to remove foodie_engagement_generator.lock" |
|
|
|
rm -f "$LOCK_DIR/foodie_engagement_generator.lock" || log "Failed to remove foodie_engagement_generator.lock" |
|
|
|
log "Stopped foodie_engagement_generator.py" |
|
|
|
log "Stopped foodie_engagement_generator.py" |
|
|
|
# Stop foodie_weekly_thread.py |
|
|
|
|
|
|
|
if pkill -TERM -f "$VENV_PYTHON.*foodie_weekly_thread"; then |
|
|
|
if pkill -TERM -f "$VENV_PYTHON.*foodie_weekly_thread"; then |
|
|
|
log "Sent TERM to foodie_weekly_thread.py" |
|
|
|
log "Sent TERM to foodie_weekly_thread.py" |
|
|
|
sleep 2 |
|
|
|
sleep 2 |
|
|
|
@ -40,13 +38,16 @@ if [ "$1" == "start" ]; then |
|
|
|
cd "$BASE_DIR" || { log "Failed to change to $BASE_DIR"; exit 1; } |
|
|
|
cd "$BASE_DIR" || { log "Failed to change to $BASE_DIR"; exit 1; } |
|
|
|
source "$BASE_DIR/venv/bin/activate" || { log "Failed to activate virtual environment"; exit 1; } |
|
|
|
source "$BASE_DIR/venv/bin/activate" || { log "Failed to activate virtual environment"; exit 1; } |
|
|
|
if [ -f "$BASE_DIR/.env" ]; then |
|
|
|
if [ -f "$BASE_DIR/.env" ]; then |
|
|
|
export $(grep -v '^#' "$BASE_DIR/.env" | xargs) |
|
|
|
while IFS='=' read -r key value; do |
|
|
|
|
|
|
|
if [[ ! -z "$key" && ! "$key" =~ ^# ]]; then |
|
|
|
|
|
|
|
export "$key=$value" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
done < <(grep -v '^#' "$BASE_DIR/.env") |
|
|
|
log ".env variables loaded" |
|
|
|
log ".env variables loaded" |
|
|
|
else |
|
|
|
else |
|
|
|
log "Error: .env file not found at $BASE_DIR/.env" |
|
|
|
log "Error: .env file not found at $BASE_DIR/.env" |
|
|
|
exit 1 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
# Start foodie_automator scripts with random 20-30 minute delays |
|
|
|
|
|
|
|
for script in foodie_automator_rss.py foodie_automator_reddit.py foodie_automator_google.py; do |
|
|
|
for script in foodie_automator_rss.py foodie_automator_reddit.py foodie_automator_google.py; do |
|
|
|
if [ -f "$script" ]; then |
|
|
|
if [ -f "$script" ]; then |
|
|
|
sleep_time=$(run_script "$script") |
|
|
|
sleep_time=$(run_script "$script") |
|
|
|
@ -58,7 +59,6 @@ if [ "$1" == "start" ]; then |
|
|
|
log "Script $script not found" |
|
|
|
log "Script $script not found" |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
# Start foodie_engagement_generator.py |
|
|
|
|
|
|
|
if [ -f "foodie_engagement_generator.py" ]; then |
|
|
|
if [ -f "foodie_engagement_generator.py" ]; then |
|
|
|
if ! check_running "foodie_engagement_generator"; then |
|
|
|
if ! check_running "foodie_engagement_generator"; then |
|
|
|
log "Running foodie_engagement_generator.py..." |
|
|
|
log "Running foodie_engagement_generator.py..." |
|
|
|
@ -68,20 +68,30 @@ if [ "$1" == "start" ]; then |
|
|
|
else |
|
|
|
else |
|
|
|
log "Script foodie_engagement_generator.py not found" |
|
|
|
log "Script foodie_engagement_generator.py not found" |
|
|
|
fi |
|
|
|
fi |
|
|
|
# Start foodie_weekly_thread.py (commented out to prevent execution) |
|
|
|
|
|
|
|
#if [ -f "foodie_weekly_thread.py" ]; then |
|
|
|
|
|
|
|
# if ! check_running "foodie_weekly_thread"; then |
|
|
|
|
|
|
|
# log "Running foodie_weekly_thread.py..." |
|
|
|
|
|
|
|
# "$VENV_PYTHON" "foodie_weekly_thread.py" >> "$BASE_DIR/logs/foodie_weekly_thread.log" 2>&1 |
|
|
|
|
|
|
|
# log "foodie_weekly_thread.py completed" |
|
|
|
|
|
|
|
# fi |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
# log "Script foodie_weekly_thread.py not found" |
|
|
|
|
|
|
|
#fi |
|
|
|
|
|
|
|
log "All scripts started. Ensure cron jobs are enabled for automatic scheduling (crontab -l)." |
|
|
|
log "All scripts started. Ensure cron jobs are enabled for automatic scheduling (crontab -l)." |
|
|
|
exit 0 |
|
|
|
exit 0 |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Handle update command |
|
|
|
|
|
|
|
if [ "$1" == "update" ]; then |
|
|
|
|
|
|
|
if [ -z "$2" ]; then |
|
|
|
|
|
|
|
log "Error: Package name required. Usage: $0 update <package_name> [version]" |
|
|
|
|
|
|
|
exit 1 |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
log "Updating package $2..." |
|
|
|
|
|
|
|
if [ -f "$BASE_DIR/update_package.sh" ]; then |
|
|
|
|
|
|
|
"$BASE_DIR/update_package.sh" "$2" "${3:-latest}" || { |
|
|
|
|
|
|
|
log "Error: Failed to update package $2" |
|
|
|
|
|
|
|
exit 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log "Package $2 updated successfully" |
|
|
|
|
|
|
|
exit 0 |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
log "Error: update_package.sh not found" |
|
|
|
|
|
|
|
exit 1 |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Directory to monitor |
|
|
|
# Directory to monitor |
|
|
|
BASE_DIR="/home/shane/foodie_automator" |
|
|
|
BASE_DIR="/home/shane/foodie_automator" |
|
|
|
CHECKSUM_FILE="$BASE_DIR/.file_checksum" |
|
|
|
CHECKSUM_FILE="$BASE_DIR/.file_checksum" |
|
|
|
@ -131,9 +141,7 @@ run_script() { |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
log "Running $script..." |
|
|
|
log "Running $script..." |
|
|
|
# Run script and capture output |
|
|
|
|
|
|
|
"$VENV_PYTHON" "$script" >> "$script_log" 2>&1 |
|
|
|
"$VENV_PYTHON" "$script" >> "$script_log" 2>&1 |
|
|
|
# Extract sleep_time from the last log line or generate random 20-30 minutes |
|
|
|
|
|
|
|
sleep_time=$(tail -n 1 "$script_log" | grep -oP 'sleep_time: \K[0-9]+' || echo $((RANDOM % 601 + 1200))) |
|
|
|
sleep_time=$(tail -n 1 "$script_log" | grep -oP 'sleep_time: \K[0-9]+' || echo $((RANDOM % 601 + 1200))) |
|
|
|
log "$script completed, sleep_time: $sleep_time seconds" |
|
|
|
log "$script completed, sleep_time: $sleep_time seconds" |
|
|
|
echo "$sleep_time" |
|
|
|
echo "$sleep_time" |
|
|
|
@ -170,15 +178,29 @@ update_dependencies() { |
|
|
|
fi |
|
|
|
fi |
|
|
|
source "$BASE_DIR/venv/bin/activate" |
|
|
|
source "$BASE_DIR/venv/bin/activate" |
|
|
|
"$VENV_PYTHON" -m pip install --upgrade pip |
|
|
|
"$VENV_PYTHON" -m pip install --upgrade pip |
|
|
|
|
|
|
|
if [ -f "requirements.lock" ]; then |
|
|
|
|
|
|
|
"$VENV_PYTHON" -m pip install -r requirements.lock || { |
|
|
|
|
|
|
|
log "Failed to install requirements.lock, falling back to requirements.txt" |
|
|
|
if [ -f "requirements.txt" ]; then |
|
|
|
if [ -f "requirements.txt" ]; then |
|
|
|
"$VENV_PYTHON" -m pip install -r requirements.txt || { |
|
|
|
"$VENV_PYTHON" -m pip install -r requirements.txt || { |
|
|
|
log "Failed to install requirements.txt, attempting fallback dependencies" |
|
|
|
log "Failed to install requirements.txt, attempting core dependencies" |
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager |
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager tweepy python-dotenv flickr-api filelock requests-oauthlib |
|
|
|
log "Fallback: Installed core dependencies" |
|
|
|
log "Fallback: Installed core dependencies" |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
log "Error: requirements.txt not found, installing core dependencies" |
|
|
|
log "Error: requirements.txt not found, installing core dependencies" |
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager |
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager tweepy python-dotenv flickr-api filelock requests-oauthlib |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elif [ -f "requirements.txt" ]; then |
|
|
|
|
|
|
|
"$VENV_PYTHON" -m pip install -r requirements.txt || { |
|
|
|
|
|
|
|
log "Failed to install requirements.txt, attempting core dependencies" |
|
|
|
|
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager tweepy python-dotenv flickr-api filelock requests-oauthlib |
|
|
|
|
|
|
|
log "Fallback: Installed core dependencies" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
log "Error: Neither requirements.lock nor requirements.txt found, installing core dependencies" |
|
|
|
|
|
|
|
"$VENV_PYTHON" -m pip install requests openai beautifulsoup4 feedparser praw duckduckgo_search selenium Pillow pytesseract webdriver-manager tweepy python-dotenv flickr-api filelock requests-oauthlib |
|
|
|
fi |
|
|
|
fi |
|
|
|
log "Dependencies updated." |
|
|
|
log "Dependencies updated." |
|
|
|
} |
|
|
|
} |
|
|
|
@ -186,40 +208,33 @@ update_dependencies() { |
|
|
|
# Main logic |
|
|
|
# Main logic |
|
|
|
log "Checking for file changes..." |
|
|
|
log "Checking for file changes..." |
|
|
|
CURRENT_CHECKSUM=$(calculate_checksum) |
|
|
|
CURRENT_CHECKSUM=$(calculate_checksum) |
|
|
|
|
|
|
|
|
|
|
|
if [ -f "$CHECKSUM_FILE" ]; then |
|
|
|
if [ -f "$CHECKSUM_FILE" ]; then |
|
|
|
PREVIOUS_CHECKSUM=$(cat "$CHECKSUM_FILE") |
|
|
|
PREVIOUS_CHECKSUM=$(cat "$CHECKSUM_FILE") |
|
|
|
else |
|
|
|
else |
|
|
|
PREVIOUS_CHECKSUM="" |
|
|
|
PREVIOUS_CHECKSUM="" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "$CURRENT_CHECKSUM" != "$PREVIOUS_CHECKSUM" ]; then |
|
|
|
if [ "$CURRENT_CHECKSUM" != "$PREVIOUS_CHECKSUM" ]; then |
|
|
|
log "File changes detected. Previous checksum: $PREVIOUS_CHECKSUM, Current checksum: $CURRENT_CHECKSUM" |
|
|
|
log "File changes detected. Previous checksum: $PREVIOUS_CHECKSUM, Current checksum: $CURRENT_CHECKSUM" |
|
|
|
|
|
|
|
|
|
|
|
# Stop scripts if running |
|
|
|
|
|
|
|
if pgrep -f "$VENV_PYTHON.*foodie_automator" > /dev/null; then |
|
|
|
if pgrep -f "$VENV_PYTHON.*foodie_automator" > /dev/null; then |
|
|
|
stop_scripts |
|
|
|
stop_scripts |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Update dependencies |
|
|
|
|
|
|
|
update_dependencies |
|
|
|
update_dependencies |
|
|
|
|
|
|
|
|
|
|
|
# Update checksum |
|
|
|
|
|
|
|
echo "$CURRENT_CHECKSUM" > "$CHECKSUM_FILE" |
|
|
|
echo "$CURRENT_CHECKSUM" > "$CHECKSUM_FILE" |
|
|
|
log "Checksum updated." |
|
|
|
log "Checksum updated." |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Run scripts sequentially if not running |
|
|
|
|
|
|
|
cd "$BASE_DIR" || { log "Failed to change to $BASE_DIR"; exit 1; } |
|
|
|
cd "$BASE_DIR" || { log "Failed to change to $BASE_DIR"; exit 1; } |
|
|
|
source "$BASE_DIR/venv/bin/activate" |
|
|
|
source "$BASE_DIR/venv/bin/activate" |
|
|
|
if [ -f "$BASE_DIR/.env" ]; then |
|
|
|
if [ -f "$BASE_DIR/.env" ]; then |
|
|
|
export $(grep -v '^#' "$BASE_DIR/.env" | xargs) |
|
|
|
while IFS='=' read -r key value; do |
|
|
|
|
|
|
|
if [[ ! -z "$key" && ! "$key" =~ ^# ]]; then |
|
|
|
|
|
|
|
export "$key=$value" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
done < <(grep -v '^#' "$BASE_DIR/.env") |
|
|
|
log ".env variables loaded" |
|
|
|
log ".env variables loaded" |
|
|
|
else |
|
|
|
else |
|
|
|
log "Error: .env file not found at $BASE_DIR/.env" |
|
|
|
log "Error: .env file not found at $BASE_DIR/.env" |
|
|
|
exit 1 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
for script in foodie_automator_rss.py foodie_automator_reddit.py foodie_automator_google.py; do |
|
|
|
for script in foodie_automator_rss.py foodie_automator_reddit.py foodie_automator_google.py; do |
|
|
|
if [ -f "$script" ]; then |
|
|
|
if [ -f "$script" ]; then |
|
|
|
sleep_time=$(run_script "$script") |
|
|
|
sleep_time=$(run_script "$script") |
|
|
|
@ -231,6 +246,5 @@ for script in foodie_automator_rss.py foodie_automator_reddit.py foodie_automato |
|
|
|
log "Script $script not found" |
|
|
|
log "Script $script not found" |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
log "All scripts processed." |
|
|
|
log "All scripts processed." |
|
|
|
exit 0 |
|
|
|
exit 0 |