This commit is contained in:
2025-11-21 12:29:41 +01:00
parent 1c0926a7f0
commit 1656f19077

View File

@@ -166,8 +166,12 @@ def get_latest_articles_by_categories(categories=None, articles_per_category=3,
# Get cluster summaries collection
cluster_summaries_collection = db['cluster_summaries']
# If no categories specified, get all available categories
# If no categories specified, get all available categories from database
if categories is None:
# Dynamically get categories from articles collection
categories = list(articles_collection.distinct('category'))
if not categories:
# Fallback to default categories if no articles exist yet
categories = ['general', 'local', 'sports', 'science']
articles = []
@@ -329,7 +333,8 @@ def get_latest_articles_by_categories(categories=None, articles_per_category=3,
# Reconstruct non-clustered list with shuffled articles
non_clustered = []
for cat in ['general', 'local', 'sports', 'science']:
# Use all categories that exist in the articles
for cat in sorted(by_category.keys()):
non_clustered.extend(by_category[cat])
# Combine: clustered first, then shuffled non-clustered
@@ -402,7 +407,8 @@ def render_newsletter_html(articles, subscriber_categories=None, tracking_enable
'general': {'name': 'Top Trending', 'icon': '🔥'},
'local': {'name': 'Local Events', 'icon': '🏛️'},
'sports': {'name': 'Sports', 'icon': ''},
'science': {'name': 'Science & Tech', 'icon': '🔬'}
'science': {'name': 'Science & Tech', 'icon': '🔬'},
'business': {'name': 'Business', 'icon': '💼'}
}
for category, category_articles in sorted(articles_by_category.items()):