From 1fba96abcb09c35aa47d3a94c0c758b2457efaa7 Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Mon, 31 May 2021 18:00:42 +0200 Subject: [PATCH] Fix exercise date parsing for non-group submissions ILIAS apparently changes the order of the fields as it sees fit, so we now try to parse *every* column, starting at from the right, as a date. The first column that parses successfully is then used. --- CHANGELOG.md | 3 +++ PFERD/crawl/ilias/kit_ilias_html.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f9ca72..34c997a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ ambiguous situations. ## Unreleased +### Fixed +- Date parsing now also works correctly in non-group exercises + ## 3.0.0 - 2021-05-31 ### Added diff --git a/PFERD/crawl/ilias/kit_ilias_html.py b/PFERD/crawl/ilias/kit_ilias_html.py index a2f30e1..64491f9 100644 --- a/PFERD/crawl/ilias/kit_ilias_html.py +++ b/PFERD/crawl/ilias/kit_ilias_html.py @@ -230,12 +230,16 @@ class IliasPage: parent_row: Tag = link.findParent("tr") children: List[Tag] = parent_row.findChildren("td") - # - # 0 1 2 3 4 name = _sanitize_path_name(children[1].getText().strip()) - date = demangle_date(children[3].getText().strip()) - log.explain(f"Found exercise detail entry {name!r}") + + for child in reversed(children): + date = demangle_date(child.getText().strip(), fail_silently=True) + if date is not None: + break + if date is None: + log.warn(f"Date parsing failed for exercise entry {name!r}") + results.append(IliasPageElement( IliasElementType.FILE, self._abs_url_from_link(link), @@ -522,7 +526,7 @@ german_months = ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', english_months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] -def demangle_date(date_str: str) -> Optional[datetime]: +def demangle_date(date_str: str, fail_silently: bool = False) -> Optional[datetime]: """ Demangle a given date in one of the following formats: "Gestern, HH:MM" @@ -554,7 +558,8 @@ def demangle_date(date_str: str) -> Optional[datetime]: return datetime(year, month, day, hour, minute) except Exception: - log.warn(f"Date parsing failed for {date_str!r}") + if not fail_silently: + log.warn(f"Date parsing failed for {date_str!r}") return None