From 74fa87ea73fa678c14e244ce34ddb081ce84ed05 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 9 Jul 2023 19:11:05 +0200 Subject: [PATCH] list menu wip --- lib/WPMenu.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index 67e5826..d101d92 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -73,7 +73,7 @@ class WPMenu: except Exception as err: self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, canalblog, err)) - def _child(self, title, parent): + def _getId(self, title, parent): menu = {"id":"", "type":"", "title": "", "parent":"", "children": []} exist = False for i in ["categories", "tags"]: @@ -100,31 +100,31 @@ class WPMenu: soup = BeautifulSoup(content, self._parser) ul = soup.find("ul", id="listsmooth") - menus = list() - menu = {"id":"", "type":"", "title": "", "parent":"", "children": []} + menu = list() parents = list() - children = list() for anchor in ul.find_all("li"): - parent = anchor.find("a").get_text() + + parent = anchor.find("a").get_text().replace(" \xa0", "") + itemMenu = {"id":"", "type":"", "title": parent, "parent": parent, "children":[]} + itemChild = {"id":"", "type":"", "title": parent, "parent": parent} href = anchor.find("a").get("href") - menu = self._child(parent, parent) + #menu = self._child(parent, parent) if href == "#": li = anchor.find("ul").find_all("li") for child in li: a = child.find("a") - self._logger.info("{0} {1} : {2}".format(self._name, anchor.find("a").get_text(), a.get_text())) - children.append(self._child(a.get_text(), parent)) - self._logger.info(children) - menu["children"] = children - menus.append(menu) - for i in range(0, len(menus)-1): - self._logger.info("{0} : Menu : {1} {2}".format(self._name, menus[i], len(parents))) - for j in range(0, len(parents)-1): - #self._logger.info("{0} : Comparaison : {1} {2}".format(self._name, menu[i]["title"], parents[j])) + self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text())) + itemChild["title"] = a.get_text() + itemChild["parent"] = parent + itemMenu["children"].append(itemChild) + menu.append(itemMenu) - if menus[i]["title"] == parents[j]: - self._logger.info("{0} del : {1}".format(self._name, parents[j])) - del parents[j] - for i in parents: - self._logger.info("{0} : Parent : {1}".format(self._name, i)) \ No newline at end of file + for i in range(0, len(menu)-1): + self._logger.info("{0} Menu : {1}".format(self._name, menu[i])) + #for j in menu[i]["children"]: + # if menu[i]["title"] == j["title"]: + # del menu[i] + + + \ No newline at end of file