From ea261c1a4c7c7ea54f24bf0a8dc001e972ffd3e3 Mon Sep 17 00:00:00 2001 From: Dongho Kim Date: Wed, 12 Nov 2025 23:20:13 +0100 Subject: [PATCH] update --- news_sender/sender_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/news_sender/sender_service.py b/news_sender/sender_service.py index 9bffc4a..74303f4 100644 --- a/news_sender/sender_service.py +++ b/news_sender/sender_service.py @@ -28,6 +28,7 @@ from tracking_integration import inject_tracking_pixel, replace_article_links, g # Load environment variables from backend/.env # Try multiple locations (Docker vs local) +# Note: override=False ensures Docker environment variables take precedence env_locations = [ Path('/app/.env'), # Docker location Path(__file__).parent.parent / 'backend' / '.env', # Local location @@ -37,7 +38,7 @@ env_locations = [ env_loaded = False for env_path in env_locations: if env_path.exists(): - load_dotenv(dotenv_path=env_path) + load_dotenv(dotenv_path=env_path, override=False) # Don't override existing env vars print(f"✓ Loaded configuration from: {env_path}") env_loaded = True break @@ -50,8 +51,8 @@ if not env_loaded: class Config: """Configuration for news sender""" - # MongoDB - MONGODB_URI = os.getenv('MONGODB_URI', 'mongodb://localhost:27017/') + # MongoDB - prioritize environment variable over .env file + MONGODB_URI = os.environ.get('MONGODB_URI') or os.getenv('MONGODB_URI', 'mongodb://localhost:27017/') DB_NAME = 'munich_news' # Email @@ -249,8 +250,11 @@ def render_newsletter_html(articles, subscriber_categories=None, tracking_enable # Filter articles by subscriber's category preferences if subscriber_categories: + print(f" Filtering for categories: {subscriber_categories}") filtered_articles = [a for a in articles if a.get('category', 'general') in subscriber_categories] + print(f" Filtered {len(articles)} articles down to {len(filtered_articles)} articles") else: + print(f" No category filter - using all {len(articles)} articles") filtered_articles = articles # Group articles by category (max 3 per category)