from datetime import datetime from html import escape from typing import Any def filter_articles( articles: list[dict[str, Any]], category_filter: str | None = None, ) -> list[dict[str, Any]]: if not category_filter: return articles wanted = category_filter.strip().lower() return [ a for a in articles if any(c.lower() == wanted for c in a.get("categories", [])) ] def create_plain_text(articles: list[dict[str, Any]], title: str) -> str: lines = [title, "=" * len(title), ""] if not articles: lines.append("Keine Artikel im gewählten Zeitraum gefunden.") return "\n".join(lines) for idx, item in enumerate(articles, start=1): stamp = _format_ts(item.get("timestamp")) cat = ", ".join(item.get("categories", [])) or "Keine Kategorie" comment = item.get("comment") or "-" lines.extend( [ f"{idx}. {item.get('title', 'Ohne Titel')}", f" Zeit: {stamp}", f" Benutzer: {item.get('user', '-')}", f" Kategorien: {cat}", f" Kommentar: {comment}", "", ] ) return "\n".join(lines).strip() def create_html(articles: list[dict[str, Any]], title: str) -> str: if not articles: return f"
Keine Artikel im gewählten Zeitraum gefunden.
" blocks = [f"