From e32a49480b007f2532c2745adf8f504c91bf9fc5 Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Mon, 28 Sep 2020 17:01:46 +0200 Subject: [PATCH] Expose methods to look up course/element names by id / url --- PFERD/ilias/crawler.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PFERD/ilias/crawler.py b/PFERD/ilias/crawler.py index c798f35..b6c65b2 100644 --- a/PFERD/ilias/crawler.py +++ b/PFERD/ilias/crawler.py @@ -153,6 +153,25 @@ class IliasCrawler: # It wasn't a course but a category list, forum, etc. return "crs_" in link_element.get("value") + def find_course_name(self, course_id: str) -> Optional[str]: + """ + Returns the name of a given course. None if it is not a valid course + or it could not be found. + """ + course_url = self._url_set_query_param( + self._base_url + "/goto.php", "target", f"crs_{course_id}" + ) + return self.find_element_name(course_url) + + def find_element_name(self, url: str) -> Optional[str]: + """ + Returns the name of the element at the given URL, if it can find one. + """ + focus_element: bs4.Tag = self._get_page(url, {}).find(id="il_mhead_t_focus") + if not focus_element: + return None + return focus_element.text + def crawl_personal_desktop(self) -> List[IliasDownloadInfo]: """ Crawls the ILIAS personal desktop (and every subelements that can be reached from there).