From 2976b4d352ac86f718d95c8a193a8bc198615b6b Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Wed, 19 May 2021 21:37:10 +0200 Subject: [PATCH] Move ILIAS file templates to own file --- PFERD/crawlers/ilias/file_templates.py | 87 ++++++++++++++++++ PFERD/crawlers/ilias/kit_web_ilias_crawler.py | 91 +------------------ 2 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 PFERD/crawlers/ilias/file_templates.py diff --git a/PFERD/crawlers/ilias/file_templates.py b/PFERD/crawlers/ilias/file_templates.py new file mode 100644 index 0000000..e9e332e --- /dev/null +++ b/PFERD/crawlers/ilias/file_templates.py @@ -0,0 +1,87 @@ +link_template_plain = "{{link}}" +link_template_rich = """ + + + + + ILIAS - Link: {{name}} + + + + + +
+ +
+
+ {{name}} +
+
{{description}}
+
+ +
+ + +""" # noqa: E501 line too long diff --git a/PFERD/crawlers/ilias/kit_web_ilias_crawler.py b/PFERD/crawlers/ilias/kit_web_ilias_crawler.py index be613e6..46eb662 100644 --- a/PFERD/crawlers/ilias/kit_web_ilias_crawler.py +++ b/PFERD/crawlers/ilias/kit_web_ilias_crawler.py @@ -13,6 +13,7 @@ from PFERD.crawler import CrawlerSection, HttpCrawler, anoncritical, arepeat from PFERD.output_dir import Redownload from PFERD.utils import soupify, url_set_query_param +from .file_templates import link_template_plain, link_template_rich from .kit_ilias_html import IliasElementType, IliasPage, IliasPageElement TargetType = Union[str, int] @@ -176,7 +177,7 @@ class KitIliasCrawler(HttpCrawler): real_url: str = html_page.select_one("a").get("href").strip() async with dl as sink: - content = _link_template_plain if self._link_file_use_plaintext else _link_template_rich + content = link_template_plain if self._link_file_use_plaintext else link_template_rich content = content.replace("{{link}}", real_url) content = content.replace("{{name}}", element.name) content = content.replace("{{description}}", str(element.description)) @@ -366,91 +367,3 @@ class KitShibbolethLogin: async def _post(session: aiohttp.ClientSession, url: str, data: Any) -> BeautifulSoup: async with session.post(url, data=data) as response: return soupify(await response.read()) - -_link_template_plain = "{{link}}" -_link_template_rich = """ - - - - - ILIAS - Link: {{name}} - - - - - -
- -
-
- {{name}} -
-
{{description}}
-
- -
- - -""" # noqa: E501 line too long