From ffda4e43df80961990b65bf99c9a96f66f7566b3 Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Tue, 25 May 2021 11:40:41 +0200 Subject: [PATCH] Add extension to link files --- PFERD/crawl/ilias/file_templates.py | 11 +++++++++++ PFERD/crawl/ilias/kit_ilias_web_crawler.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PFERD/crawl/ilias/file_templates.py b/PFERD/crawl/ilias/file_templates.py index 1385ba4..6f2b1cd 100644 --- a/PFERD/crawl/ilias/file_templates.py +++ b/PFERD/crawl/ilias/file_templates.py @@ -112,6 +112,17 @@ class Links(Enum): return None raise ValueError("Missing switch case") + def extension(self) -> Optional[str]: + if self == self.FANCY: + return ".html" + elif self == self.PLAIN: + return ".txt" + elif self == self.INTERNET_SHORTCUT: + return ".url" + elif self == self.IGNORE: + return None + raise ValueError("Missing switch case") + @staticmethod def from_string(string: str) -> "Links": try: diff --git a/PFERD/crawl/ilias/kit_ilias_web_crawler.py b/PFERD/crawl/ilias/kit_ilias_web_crawler.py index 283289e..318fa5e 100644 --- a/PFERD/crawl/ilias/kit_ilias_web_crawler.py +++ b/PFERD/crawl/ilias/kit_ilias_web_crawler.py @@ -304,12 +304,14 @@ class KitIliasWebCrawler(HttpCrawler): log.explain(f"Links type is {self._links}") link_template_maybe = self._links.template() - if not link_template_maybe: + link_extension = self._links.extension() + if not link_template_maybe or not link_extension: log.explain("Answer: No") return else: log.explain("Answer: Yes") link_template = link_template_maybe + element_path = element_path.with_name(element_path.name + link_extension) maybe_dl = await self.download(element_path, mtime=element.mtime) if not maybe_dl: