#!/bin/bash # POTE Automated Daily Run # This script should be run by cron daily (e.g., at 6 AM after market close) # # Example crontab entry: # 0 6 * * * /home/poteapp/pote/scripts/automated_daily_run.sh >> /home/poteapp/logs/daily_run.log 2>&1 set -e # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" LOG_DIR="${LOG_DIR:-$HOME/logs}" VENV_PATH="${VENV_PATH:-$PROJECT_ROOT/venv}" REPORT_RECIPIENTS="${REPORT_RECIPIENTS:-admin@localhost}" # Create log directory if it doesn't exist mkdir -p "$LOG_DIR" # Timestamp for logging TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') echo "===============================================" echo "POTE Automated Daily Run - $TIMESTAMP" echo "===============================================" # Activate virtual environment if [ -d "$VENV_PATH" ]; then echo "Activating virtual environment..." source "$VENV_PATH/bin/activate" else echo "WARNING: Virtual environment not found at $VENV_PATH" echo "Attempting to use system Python..." fi # Change to project directory cd "$PROJECT_ROOT" # Load environment variables if [ -f ".env" ]; then echo "Loading environment variables from .env..." export $(grep -v '^#' .env | xargs) fi # Step 1: Fetch new congressional trades echo "" echo "[1/6] Fetching congressional trades..." if python scripts/fetch_congressional_trades.py; then echo "✓ Congressional trades fetched successfully" else echo "⚠ Warning: Failed to fetch congressional trades (may be API issue)" fi # Step 2: Enrich securities (get company names, sectors) echo "" echo "[2/6] Enriching security data..." if python scripts/enrich_securities.py; then echo "✓ Securities enriched successfully" else echo "⚠ Warning: Failed to enrich securities" fi # Step 3: Fetch latest price data echo "" echo "[3/6] Fetching price data..." if python scripts/fetch_sample_prices.py; then echo "✓ Price data fetched successfully" else echo "⚠ Warning: Failed to fetch price data" fi # Step 4: Run market monitoring echo "" echo "[4/6] Running market monitoring..." if python scripts/monitor_market.py --scan; then echo "✓ Market monitoring completed" else echo "⚠ Warning: Market monitoring failed" fi # Step 5: Analyze disclosure timing echo "" echo "[5/6] Analyzing disclosure timing..." if python scripts/analyze_disclosure_timing.py --recent 7 --save /tmp/pote_timing_analysis.txt; then echo "✓ Disclosure timing analysis completed" else echo "⚠ Warning: Disclosure timing analysis failed" fi # Step 6: Send daily report echo "" echo "[6/6] Sending daily report..." if python scripts/send_daily_report.py --to "$REPORT_RECIPIENTS" --save-to-file "$LOG_DIR/daily_report_$(date +%Y%m%d).txt"; then echo "✓ Daily report sent successfully" else echo "✗ ERROR: Failed to send daily report" exit 1 fi # Final summary echo "" echo "===============================================" echo "Daily run completed successfully at $(date '+%Y-%m-%d %H:%M:%S')" echo "===============================================" # Clean up old log files (keep last 30 days) find "$LOG_DIR" -name "daily_report_*.txt" -mtime +30 -delete 2>/dev/null || true exit 0