#!/usr/bin/env python3 from __future__ import annotations import sys from datetime import date from app_config import get_settings from movie_pipeline import get_upcoming_movie_records def truncate(text: str, max_len: int) -> str: if len(text) <= max_len: return text if max_len <= 3: return text[:max_len] return text[: max_len - 3] + "..." def format_table(headers: list[str], rows: list[list[str]]) -> str: max_widths = [36, 24, 24, 12, 8, 60] default_max_width = 40 widths = [len(h) for h in headers] for row in rows: for i, cell in enumerate(row): max_width = max_widths[i] if i < len(max_widths) else default_max_width widths[i] = min(max(widths[i], len(cell)), max_width) lines = [] header_line = " | ".join(truncate(h, widths[i]).ljust(widths[i]) for i, h in enumerate(headers)) sep_line = "-+-".join("-" * w for w in widths) lines.append(header_line) lines.append(sep_line) for row in rows: line = " | ".join(truncate(row[i], widths[i]).ljust(widths[i]) for i in range(len(headers))) lines.append(line) return "\n".join(lines) def get_upcoming_movie_rows(locale: str, today: date | None = None) -> list[list[str]]: records = get_upcoming_movie_records(locale, today=today) rows = [] for item in records: rows.append( [ item["title"], item["studio"], item["genres"], item["release"], item["anilist_url"], ] ) return rows def main() -> int: settings = get_settings() locale = settings.locale try: rows = get_upcoming_movie_rows(locale) except Exception as exc: print(f"Fehler beim Datenabruf: {exc}", file=sys.stderr) return 1 if not rows: print("Keine Anime Filme fuer diesen und naechsten Monat gefunden.") return 0 headers = ["Title", "Studio", "Genres", "Release", "AniList"] print(format_table(headers, rows)) return 0 if __name__ == "__main__": raise SystemExit(main())