Add extension to link files

This commit is contained in:
I-Al-Istannen 2021-05-25 11:40:41 +02:00
parent 69cb2a7734
commit ffda4e43df
2 changed files with 14 additions and 1 deletions

View File

@ -112,6 +112,17 @@ class Links(Enum):
return None return None
raise ValueError("Missing switch case") 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 @staticmethod
def from_string(string: str) -> "Links": def from_string(string: str) -> "Links":
try: try:

View File

@ -304,12 +304,14 @@ class KitIliasWebCrawler(HttpCrawler):
log.explain(f"Links type is {self._links}") log.explain(f"Links type is {self._links}")
link_template_maybe = self._links.template() 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") log.explain("Answer: No")
return return
else: else:
log.explain("Answer: Yes") log.explain("Answer: Yes")
link_template = link_template_maybe 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) maybe_dl = await self.download(element_path, mtime=element.mtime)
if not maybe_dl: if not maybe_dl: