From 057135022fe9cb81204af39d83f0e3f1a7507452 Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Fri, 8 May 2020 22:10:43 +0200 Subject: [PATCH] Try to accept that life sometimes is in English --- PFERD/ilias/date_demangler.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PFERD/ilias/date_demangler.py b/PFERD/ilias/date_demangler.py index 048df70..9c1fc8d 100644 --- a/PFERD/ilias/date_demangler.py +++ b/PFERD/ilias/date_demangler.py @@ -24,12 +24,17 @@ def demangle_date(date: str) -> Optional[datetime.datetime]: """ saved = locale.setlocale(locale.LC_ALL) try: - locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') + try: + locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') + except locale.Error: + PRETTY.warning( + "Could not set language to german. Assuming you use english everywhere." + ) date = re.sub(r"\s+", " ", date) - date = date.replace("Gestern", _yesterday().strftime("%d. %b %Y")) - date = date.replace("Heute", datetime.date.today().strftime("%d. %b %Y")) - date = date.replace("Morgen", _tomorrow().strftime("%d. %b %Y")) + date = re.sub("Gestern|Yesterday", _yesterday().strftime("%d. %b %Y"), date, re.I) + date = re.sub("Heute|Today", datetime.date.today().strftime("%d. %b %Y"), date, re.I) + date = re.sub("Morgen|Tomorrow", _tomorrow().strftime("%d. %b %Y"), date, re.I) return datetime.datetime.strptime(date, "%d. %b %Y, %H:%M") except ValueError: PRETTY.warning(f"Could not parse date {date!r}")