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
8.5 KiB
Automation and Reporting Guide
This guide covers automated data updates, email reporting, and CI/CD pipelines for POTE.
Table of Contents
Email Reporting Setup
Configure SMTP Settings
POTE can send automated email reports. You need to configure SMTP settings in your .env file.
Option 1: Gmail
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password # NOT your regular password!
FROM_EMAIL=pote-reports@gmail.com
REPORT_RECIPIENTS=user1@example.com,user2@example.com
Important: For Gmail, you must use an App Password, not your regular password:
- Enable 2-factor authentication on your Google account
- Go to https://myaccount.google.com/apppasswords
- Generate an app password for "Mail"
- Use that 16-character password in
.env
Option 2: SendGrid
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=your-sendgrid-api-key
FROM_EMAIL=noreply@yourdomain.com
REPORT_RECIPIENTS=user1@example.com,user2@example.com
Option 3: Custom SMTP Server
SMTP_HOST=mail.yourdomain.com
SMTP_PORT=587 # or 465 for SSL
SMTP_USER=your-username
SMTP_PASSWORD=your-password
FROM_EMAIL=pote@yourdomain.com
REPORT_RECIPIENTS=admin@yourdomain.com
Test SMTP Connection
Before setting up automation, test your SMTP settings:
python scripts/send_daily_report.py --to your-email@example.com --test-smtp
Manual Report Generation
Send Daily Report
python scripts/send_daily_report.py --to user@example.com
Options:
--to EMAIL- Recipient(s), comma-separated--date YYYY-MM-DD- Report date (default: today)--test-smtp- Test SMTP connection first--save-to-file PATH- Also save report to file
Send Weekly Report
python scripts/send_weekly_report.py --to user@example.com
Automated Daily/Weekly Runs
POTE includes shell scripts for automated execution:
Daily Run Script
scripts/automated_daily_run.sh performs:
- Fetch congressional trades
- Enrich securities (company names, sectors)
- Fetch latest price data
- Run market monitoring
- Analyze disclosure timing
- Send daily report via email
Weekly Run Script
scripts/automated_weekly_run.sh performs:
- Generate pattern detection report
- Send weekly summary via email
Manual Execution
Test the scripts manually before setting up cron:
# Daily run
./scripts/automated_daily_run.sh
# Weekly run
./scripts/automated_weekly_run.sh
Check logs:
tail -f ~/logs/daily_run.log
tail -f ~/logs/weekly_run.log
Cron Setup
Automated Setup (Recommended)
Use the interactive setup script:
cd /path/to/pote
./scripts/setup_cron.sh
This will:
- Prompt for your email address
- Ask for preferred schedule
- Configure
.envwith email settings - Add cron jobs
- Backup existing crontab
Manual Setup
If you prefer manual configuration:
- Make scripts executable:
chmod +x scripts/automated_daily_run.sh
chmod +x scripts/automated_weekly_run.sh
- Create logs directory:
mkdir -p ~/logs
- Edit crontab:
crontab -e
- Add these lines:
# POTE Automated Daily Run (6 AM daily)
0 6 * * * /home/poteapp/pote/scripts/automated_daily_run.sh >> /home/poteapp/logs/daily_run.log 2>&1
# POTE Automated Weekly Run (Sunday 8 AM)
0 8 * * 0 /home/poteapp/pote/scripts/automated_weekly_run.sh >> /home/poteapp/logs/weekly_run.log 2>&1
Verify Cron Jobs
crontab -l
Remove Cron Jobs
crontab -e
# Delete the POTE lines and save
Health Checks
Run Health Check
python scripts/health_check.py
Output:
============================================================
POTE HEALTH CHECK
============================================================
Timestamp: 2025-12-15T10:30:00
Overall Status: ✓ OK
✓ Database Connection: Database connection successful
✓ Data Freshness: Data is fresh (2 days old)
latest_trade_date: 2025-12-13
✓ Data Counts: Database has 1,234 trades
officials: 45
securities: 123
trades: 1,234
prices: 12,345
market_alerts: 567
✓ Recent Alerts: 23 alerts in last 24 hours
============================================================
JSON Output
For programmatic use:
python scripts/health_check.py --json
Integrate with Monitoring
Add health check to cron for monitoring:
# POTE Health Check (every 6 hours)
0 */6 * * * /home/poteapp/pote/venv/bin/python /home/poteapp/pote/scripts/health_check.py >> /home/poteapp/logs/health.log 2>&1
CI/CD Pipeline
POTE includes a GitHub Actions / Gitea Actions compatible CI/CD pipeline.
What the Pipeline Does
On every push or pull request:
-
Lint & Test
- Runs ruff, black, mypy
- Executes full test suite with coverage
- Tests against PostgreSQL
-
Security Scan
- Checks dependencies with
safety - Scans code with
bandit
- Checks dependencies with
-
Dependency Scan
- Scans for vulnerabilities with Trivy
-
Docker Build Test
- Builds Docker image
- Verifies POTE imports correctly
GitHub Actions Setup
The pipeline is at .github/workflows/ci.yml and will run automatically when you push to GitHub.
Gitea Actions Setup
Gitea Actions is compatible with GitHub Actions syntax. To enable:
- Ensure Gitea Actions runner is installed on your server
- Push the repository to Gitea
- The workflow will run automatically
Local Testing
Test the pipeline locally with Docker:
# Build image
docker build -t pote:test .
# Run tests in container
docker run --rm pote:test pytest tests/
Secrets Configuration
For the CI pipeline to work fully, configure these secrets in your repository settings:
SONAR_HOST_URL(optional, for SonarQube)SONAR_TOKEN(optional, for SonarQube)
Deployment Workflow
Development → Production
-
Develop locally
git checkout -b feature/my-feature # Make changes pytest tests/ git commit -m "Add feature" -
Push and test
git push origin feature/my-feature # CI pipeline runs automatically -
Merge to main
# After PR approval git checkout main git pull -
Deploy to Proxmox
ssh poteapp@10.0.10.95 cd ~/pote git pull source venv/bin/activate pip install -e . alembic upgrade head -
Restart services
# If using systemd sudo systemctl restart pote # Or just restart cron jobs (they'll pick up changes) # No action needed
Troubleshooting
Email Not Sending
- Check SMTP settings in
.env - Test connection:
python scripts/send_daily_report.py --to your-email@example.com --test-smtp - For Gmail: Ensure you're using an App Password, not regular password
- Check firewall: Ensure port 587 (or 465) is open
Cron Jobs Not Running
-
Check cron service is running:
systemctl status cron -
Verify cron jobs are installed:
crontab -l -
Check logs for errors:
tail -f ~/logs/daily_run.log -
Ensure scripts are executable:
chmod +x scripts/automated_*.sh -
Check paths in crontab (use absolute paths)
No Data in Reports
-
Run health check:
python scripts/health_check.py -
Manually fetch data:
python scripts/fetch_congressional_trades.py python scripts/enrich_securities.py -
Check database connection in
.env
Summary
After deployment, you have three ways to use POTE:
- Manual: SSH to server, run scripts manually
- Automated (Recommended): Set up cron jobs, receive daily/weekly email reports
- Programmatic: Use the Python API directly in your scripts
For fully automated operation:
# One-time setup
cd /path/to/pote
./scripts/setup_cron.sh
# That's it! You'll now receive:
# - Daily reports at 6 AM (or your chosen time)
# - Weekly reports on Sundays at 8 AM
# - Reports will be sent to your configured email
To access reports without email:
- Reports are saved to
~/logs/daily_report_YYYYMMDD.txt - Reports are saved to
~/logs/weekly_report_YYYYMMDD.txt - You can SSH to the server and read them directly