Made the randam locale date optional, default just Dutch

This commit is contained in:
mailcat
2026-08-17 09:21:11 +02:00
parent 0b4e702bac
commit d70112d766
2 changed files with 158 additions and 4 deletions
+18 -4
View File
@@ -131,6 +131,19 @@ def get_random_locale() -> (str, str, str):
code = all_ids[random.randrange(0, len(all_ids))]
return (code, babel.Locale(code).language_name, babel.Locale(code).english_name)
def create_mail_subject(zoekdatum, random = False) -> str:
# Als random = true, toon dan de datum ook in een willekeurige andere taal
# Anders alleen in het Nederlands
datum_nl = format_date(zoekdatum, "EEEE d MMMM yyyy", locale="nl")
if random:
random_locale, random_lang, random_elang = get_random_locale()
datum_bl = format_date(zoekdatum, locale=random_locale)
return f"Mailoverzicht van {datum_bl} ({random_lang} - {random_elang}) of {datum_nl}"
else:
return f"Mailoverzicht van {datum_nl}"
# ── IMAP ophalen ──────────────────────────────────────────────────────────────
def haal_berichten_op(mail: imaplib.IMAP4_SSL, zoekdatum: date) -> dict[str, list[dict]]:
@@ -266,11 +279,12 @@ def bouw_html(berichten: dict[str, list[dict]], zoekdatum: date) -> str:
# ── e-mail versturen ──────────────────────────────────────────────────────────
def stuur_overzicht(html: str, zoekdatum: date, config: dict):
datum_nl = format_date(zoekdatum, "EEEE d MMMM yyyy", locale="nl") # zoekdatum.strftime("%-d %B %Y")
random_locale, random_lang, random_elang = get_random_locale()
datum_bl = format_date(zoekdatum, locale=random_locale)
# datum_nl = format_date(zoekdatum, "EEEE d MMMM yyyy", locale="nl") # zoekdatum.strftime("%-d %B %Y")
# random_locale, random_lang, random_elang = get_random_locale()
# datum_bl = format_date(zoekdatum, locale=random_locale)
msg = MIMEMultipart("alternative")
msg["Subject"] = f"Mailoverzicht van {datum_bl} ({random_lang} - {random_elang}) of {datum_nl}"
# msg["Subject"] = f"Mailoverzicht van {datum_bl} ({random_lang} - {random_elang}) of {datum_nl}"
msg["Subject"] = create_mail_subject(zoekdatum, False)
msg["From"] = config["from"]
msg["To"] = config["to"]
msg.attach(MIMEText(html, "html", "utf-8"))