YouCut_20250731_214558173.mp4
An intelligent, automated newsletter generation system that crawls the web for AI and tech news, processes it through multiple AI agents, and delivers personalized newsletters via email.
- Automated Web Crawling: Uses Crawl4AI to gather real-time news from multiple sources
- Multi-Agent Processing: LangGraph orchestrates different AI agents (Research, Analysis, Opinion, Editor)
- Smart Scheduling: Configurable schedule for automatic newsletter generation
- Email Delivery: Gmail API integration for professional email delivery
- Web Dashboard: FastAPI-based monitoring and management interface
- Docker Support: Easy deployment with Docker containers
- Extensible Architecture: Modular design for easy customization
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Scheduler │───▶│ Web Crawler │───▶│ Multi-Agent │
│ (schedule) │ │ (Crawl4AI) │ │ (LangGraph) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
┌─────────────────┐ ┌──────────────────┐ │
│ Email Service │◀───│ Newsletter │◀────────────┘
│ (Gmail API) │ │ Formatter │
└─────────────────┘ └──────────────────┘
- Python 3.11+
- OpenRouter API key
- Gmail API credentials
- Docker (optional)
-
Clone the repository
git clone <repository-url> cd Newsletter_aaa
-
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env with your API keys and configuration
-
Set up Gmail API
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API
- Create credentials (OAuth 2.0 Client ID)
- Download
credentials.json
to project root
-
Run the application
# Run once python main.py --mode once # Start scheduler python main.py --mode schedule # Check configuration python main.py --config-check
# OpenRouter API Configuration
OPENROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
# Gmail API Configuration
GMAIL_CREDENTIALS_PATH=credentials.json
GMAIL_TOKEN_PATH=token.json
# Newsletter Configuration
SENDER_EMAIL=your_email@gmail.com
RECIPIENT_EMAILS=recipient1@example.com,recipient2@example.com
NEWSLETTER_TITLE=Daily AI Newsletter
# Scheduling Configuration
SCHEDULE_TIMES=08:00,18:00
TIMEZONE=Asia/Kolkata
# Crawling Configuration
MAX_ARTICLES_PER_TOPIC=5
CRAWL_TIMEOUT=30
# LLM Configuration
DEFAULT_MODEL=gpt-4-turbo-preview
TEMPERATURE=0.7
MAX_TOKENS=2000
Edit config.py
to customize topics:
TOPICS = [
"AI news",
"Machine Learning breakthroughs",
"Tech startups",
"OpenAI updates",
"Google AI developments",
"Tech industry trends"
]
# Build and start services
docker-compose -f docker/docker-compose.yml up -d
# View logs
docker-compose -f docker/docker-compose.yml logs -f
# Stop services
docker-compose -f docker/docker-compose.yml down
# Build image
docker build -f docker/Dockerfile -t ai-newsletter-agent .
# Run container
docker run -d \
--name newsletter-agent \
--env-file .env \
-v $(pwd)/logs:/app/logs \
-v $(pwd)/credentials.json:/app/credentials.json:ro \
-p 8000:8000 \
ai-newsletter-agent
Access the web dashboard at http://localhost:8000
when running the FastAPI server:
# Start API server
python -m uvicorn api.fastapi_server:app --host 0.0.0.0 --port 8000
GET /
- Dashboard homepageGET /status
- System statusPOST /generate
- Generate newsletter immediatelyGET /history
- Newsletter generation historyPOST /schedule/start
- Start schedulerPOST /schedule/stop
- Stop schedulerGET /config
- Get configurationPOST /config
- Update configurationGET /health
- Health check
# Generate newsletter once
python main.py --mode once
# Start scheduled service
python main.py --mode schedule
# Check configuration
python main.py --config-check
# Generate newsletter via API
curl -X POST http://localhost:8000/generate
# Check status
curl http://localhost:8000/status
# Start scheduler
curl -X POST http://localhost:8000/schedule/start
from scheduler.newsletter_scheduler import NewsletterScheduler
# Create scheduler instance
scheduler = NewsletterScheduler()
# Run once
scheduler.run_once()
# Start scheduled service
scheduler.start_scheduler()
- Uses Crawl4AI for intelligent web scraping
- Supports RSS feeds and direct URL crawling
- Filters content by relevance and recency
- Research Agent: Categorizes and summarizes articles
- Analysis Agent: Provides deep insights and implications
- Opinion Agent: Adds editorial commentary
- Editor Agent: Compiles final newsletter with formatting
- OpenRouter API integration
- Retry logic and error handling
- Configurable models and parameters
- Gmail API integration
- HTML email formatting
- Batch sending support
- Configurable scheduling
- Async workflow orchestration
- Error handling and logging
- Logs are stored in
logs/
directory - Daily log rotation
- Structured logging with timestamps
- Health check endpoints for monitoring
- API keys stored in environment variables
- OAuth 2.0 for Gmail API authentication
- No sensitive data in logs
- Docker secrets support
- Async/await for concurrent operations
- Connection pooling for HTTP requests
- Caching for frequently accessed data
- Use environment-specific configurations
- Set up monitoring and alerting
- Configure log aggregation
- Use a process manager (PM2, systemd)
- Set up reverse proxy (nginx)
- Health check endpoints
- Metrics collection
- Error tracking
- Performance monitoring
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Gmail API Authentication
- Ensure
credentials.json
is in the project root - Check OAuth consent screen configuration
- Verify Gmail API is enabled
- Ensure
-
OpenRouter API Issues
- Verify API key is correct
- Check rate limits
- Ensure sufficient credits
-
Crawling Issues
- Some sites may block automated requests
- Adjust timeout settings
- Check network connectivity
-
Scheduling Issues
- Verify timezone configuration
- Check system time
- Review log files for errors
# Enable debug logging
export LOG_LEVEL=DEBUG
python main.py --mode once
For issues and questions:
- Check the logs in
logs/
directory - Review configuration settings
- Check API credentials and permissions
- Consult the troubleshooting section
Built with ❤️ using Python, Crawl4AI, LangGraph, OpenRouter, and Gmail API.