Garmelon/PFERD

Desktop: Direkte Dateilinks führen zu Error

oders opened this issue · 2 comments

oders commented

Wenn eine Datei (z.B. "Skript.pdf") direkt auf den Desktop gelegt ist, bricht der Crawler dort ab.

Manche Profs erweitern das Skript jede Woche. Es kann hilfreich sein, die Datei direkt auf dem Desktop zu haben.
Der Crawler bricht ab, weil diese Datei dort ohne Properties angezeigt wird:

------------------ Output ----------------------------

Error An unexpected exception occurred

Traceback (most recent call last):
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/pferd.py", line 156, in run
    await crawler.run()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/http_crawler.py", line 193, in run
    await super().run()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/crawler.py", line 82, in wrapper
    return await f(*args, **kwargs)
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/crawler.py", line 333, in run
    await self._run()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_web_crawler.py", line 189, in _run
    await self._crawl_desktop()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_web_crawler.py", line 203, in _crawl_desktop
    await self._crawl_url(self._base_url)
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_web_crawler.py", line 231, in _crawl_url
    await gather_elements()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_web_crawler.py", line 93, in wrapper
    return await f(*args, **kwargs)
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_web_crawler.py", line 228, in gather_elements
    elements.extend(page.get_child_elements())
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_html.py", line 74, in get_child_elements
    return self._find_normal_entries()
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_html.py", line 352, in _find_normal_entries
    result.append(self._file_to_element(element_name, abs_url, link))
  File "/home/kali/.local/lib/python3.9/site-packages/PFERD/crawl/ilias/kit_ilias_html.py", line 419, in _file_to_element
    file_type = properties_parent.select_one("span.il_ItemProperty").getText().strip()
AttributeError: 'NoneType' object has no attribute 'select_one'

--------------------- Output Ende -------------------------

oders commented

Mein eigener Hot-Fix für heute:

PFERD/crawl/ilias/kit_ilias_html.py -> Zeile 419:

try: 
    file_type = properties_parent.select_one("span.il_ItemProperty").getText().strip()
except:
    log.explain(f"Direkte Links zu Dateien auf dem Desktop können noch nicht verarbeitet werden.")
    file_type = "unknown" #eieiei... harter hot-fix
    fix_path = name + "." + file_type
    return IliasPageElement(IliasElementType.FILE, url, fix_path)

Aber das geht bestimmt schöner und konsistenter.