#!/bin/bash
# Wrapper script for cron execution
# Usage: ./run_hourly.sh [--skip-notebook]
#   --skip-notebook: Skip notebook execution, only upload existing plot

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

# Initialize conda
CONDA_BASE=$(conda info --base 2>/dev/null)
if [ -z "$CONDA_BASE" ]; then
    # Try common conda locations if conda not in PATH
    for CONDA_LOC in "$HOME/anaconda3" "$HOME/miniconda3" "/opt/conda"; do
        if [ -d "$CONDA_LOC" ]; then
            CONDA_BASE="$CONDA_LOC"
            break
        fi
    done
fi

# Source conda
if [ -f "$CONDA_BASE/etc/profile.d/conda.sh" ]; then
    source "$CONDA_BASE/etc/profile.d/conda.sh"
    conda activate suno_env_dev
else
    echo "Error: Cannot find conda initialization script" >&2
    exit 1
fi

# Run the Python script with arguments passed through
python run_and_notify.py "$@"

# Exit with the same code as the Python script
exit $?
