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.
This commit is contained in:
I-Al-Istannen 2021-05-31 18:00:42 +02:00
parent 921cec7ddc
commit 1fba96abcb
2 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -230,12 +230,16 @@ class IliasPage:
parent_row: Tag = link.findParent("tr")
children: List[Tag] = parent_row.findChildren("td")
# <checkbox> <name> <uploader> <date> <download>
# 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