From bca529f3c30349339bf9908b71921007d53eab88 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 11 Jul 2023 21:39:41 +0200 Subject: [PATCH] parent and children array --- lib/WPMenu.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index c87e585..fa739d7 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -109,10 +109,7 @@ class WPMenu: href = anchor.find("a").get("href") if href == "{0}://{1}/".format(self._protocol_canalblog, self._canalblog): parent = "home" - itemMenu = {"id":"", "type":"", "title": parent, "children":list()} - - - #menu = self._child(parent, parent) + itemMenu = {"id":"", "type":"", "title": parent, "children":list()} if href == "#": li = anchor.find("ul").find_all("li") for child in li: @@ -122,13 +119,16 @@ class WPMenu: menu.append(itemMenu) - for i in range(0, len(children)-1): - self._logger.info("{0} : Child {1}".format(self._name, children[i])) - for j in range(0, len(menu)-1): - if menu[j]["title"] == children[i]["title"]: - self._logger.info("{0} : Parent {1}".format(self._name, menu[j])) - del menu[j] - for j in range(0, len(menu)-1): + for i in range(0, len(children)): + self._logger.info("{0} : Child {1} {2}".format(self._name, children[i], i)) + for j in range(0, len(menu)): + if j < len(menu): + if menu[j]["title"] == children[i]["title"]: + self._logger.info("{0} : Parent {1} {2}".format(self._name, menu[j], j)) + del menu[j] + + for j in range(0, len(menu)): + self._logger.info("{0} : Children for : {1}".format(self._name, menu[j]["title"])) if menu[j]["title"] == children[i]["parent"]: menu[j]["children"].append({"id":"", "title":children[i]["title"], "parent": children[i]["parent"]})