This commit is contained in:
2025-11-12 23:20:13 +01:00
parent e5e1414a9f
commit ea261c1a4c

View File

@@ -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)