POTE/scripts/pre_market_close_update.sh
ilia 0d8d85adc1 Add complete automation, reporting, and CI/CD system
Features Added:
==============

📧 EMAIL REPORTING SYSTEM:
- EmailReporter: Send reports via SMTP (Gmail, SendGrid, custom)
- ReportGenerator: Generate daily/weekly summaries with HTML/text formatting
- Configurable via .env (SMTP_HOST, SMTP_PORT, etc.)
- Scripts: send_daily_report.py, send_weekly_report.py

🤖 AUTOMATED RUNS:
- automated_daily_run.sh: Full daily ETL pipeline + reporting
- automated_weekly_run.sh: Weekly pattern analysis + reports
- setup_cron.sh: Interactive cron job setup (5-minute setup)
- Logs saved to ~/logs/ with automatic cleanup

🔍 HEALTH CHECKS:
- health_check.py: System health monitoring
- Checks: DB connection, data freshness, counts, recent alerts
- JSON output for programmatic use
- Exit codes for monitoring integration

🚀 CI/CD PIPELINE:
- .github/workflows/ci.yml: Full CI/CD pipeline
- GitHub Actions / Gitea Actions compatible
- Jobs: lint & test, security scan, dependency scan, Docker build
- PostgreSQL service for integration tests
- 93 tests passing in CI

📚 COMPREHENSIVE DOCUMENTATION:
- AUTOMATION_QUICKSTART.md: 5-minute email setup guide
- docs/12_automation_and_reporting.md: Full automation guide
- Updated README.md with automation links
- Deployment → Production workflow guide

🛠️ IMPROVEMENTS:
- All shell scripts made executable
- Environment variable examples in .env.example
- Report logs saved with timestamps
- 30-day log retention with auto-cleanup
- Health checks can be scheduled via cron

WHAT THIS ENABLES:
==================
After deployment, users can:
1. Set up automated daily/weekly email reports (5 min)
2. Receive HTML+text emails with:
   - New trades, market alerts, suspicious timing
   - Weekly patterns, rankings, repeat offenders
3. Monitor system health automatically
4. Run full CI/CD pipeline on every commit
5. Deploy with confidence (tests + security scans)

USAGE:
======
# One-time setup (on deployed server)
./scripts/setup_cron.sh

# Or manually send reports
python scripts/send_daily_report.py --to user@example.com
python scripts/send_weekly_report.py --to user@example.com

# Check system health
python scripts/health_check.py

See AUTOMATION_QUICKSTART.md for full instructions.

93 tests passing | Full CI/CD | Email reports ready
2025-12-15 15:34:31 -05:00

87 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# Pre-Market-Close POTE Update
# Run at 3 PM ET (1 hour before market close)
# Fetches latest disclosures and generates actionable report
set -e
# --- Configuration ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
LOG_DIR="${PROJECT_DIR}/logs"
REPORT_DIR="${PROJECT_DIR}/reports"
LOG_FILE="${LOG_DIR}/pre_market_$(date +%Y%m%d).log"
REPORT_FILE="${REPORT_DIR}/trading_report_$(date +%Y%m%d).txt"
# Ensure directories exist
mkdir -p "$LOG_DIR" "$REPORT_DIR"
# Redirect output to log
exec > >(tee -a "$LOG_FILE") 2>&1
echo "=========================================="
echo " POTE Pre-Market-Close Update"
echo " $(date)"
echo " Running 1 hour before market close"
echo "=========================================="
# Activate virtual environment
cd "$PROJECT_DIR"
source venv/bin/activate
# --- Step 1: Quick Fetch of New Trades ---
echo ""
echo "--- Fetching Latest Congressional Trades ---"
python scripts/fetch_congressional_trades.py --days 3
FETCH_EXIT=$?
if [ $FETCH_EXIT -ne 0 ]; then
echo "⚠️ WARNING: Failed to fetch trades (API may be down)"
echo " Generating report from existing data..."
fi
# --- Step 2: Quick Security Enrichment ---
echo ""
echo "--- Enriching New Securities ---"
python scripts/enrich_securities.py --limit 10
ENRICH_EXIT=$?
# --- Step 3: Generate Trading Report ---
echo ""
echo "--- Generating Trading Report ---"
python scripts/generate_trading_report.py \
--days 7 \
--watchlist-only \
--format text \
--output "$REPORT_FILE"
REPORT_EXIT=$?
if [ $REPORT_EXIT -eq 0 ]; then
echo "✅ Report saved to: $REPORT_FILE"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 REPORT PREVIEW"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
cat "$REPORT_FILE"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
else
echo "❌ Failed to generate report"
fi
# --- Step 4: Optional Price Update (Quick) ---
# Uncomment if you want prices updated before market close
# echo ""
# echo "--- Quick Price Update ---"
# python scripts/fetch_sample_prices.py --days 5
echo ""
echo "=========================================="
echo " Update Complete - $(date)"
echo "=========================================="
# Exit successfully even if some steps warned
exit 0