menu and sub-menu wip

This commit is contained in:
Valentin CZERYBA 2023-07-09 21:42:09 +02:00
parent 74fa87ea73
commit 20c4adb3cf

View File

@ -101,30 +101,34 @@ class WPMenu:
soup = BeautifulSoup(content, self._parser) soup = BeautifulSoup(content, self._parser)
ul = soup.find("ul", id="listsmooth") ul = soup.find("ul", id="listsmooth")
menu = list() menu = list()
parents = list() children = list()
for anchor in ul.find_all("li"): for anchor in ul.find_all("li"):
parent = anchor.find("a").get_text().replace(" \xa0", "") parent = anchor.find("a").get_text().replace(" \xa0", "")
itemMenu = {"id":"", "type":"", "title": parent, "parent": parent, "children":[]} itemMenu = {"id":"", "type":"", "title": parent, "children":list()}
itemChild = {"id":"", "type":"", "title": parent, "parent": parent}
href = anchor.find("a").get("href") href = anchor.find("a").get("href")
if href == self._wordpress:
parent = "home"
#menu = self._child(parent, parent) #menu = self._child(parent, parent)
if href == "#": if href == "#":
li = anchor.find("ul").find_all("li") li = anchor.find("ul").find_all("li")
for child in li: for child in li:
a = child.find("a") a = child.find("a")
self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text())) self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text()))
itemChild["title"] = a.get_text() children.append({"title": a.get_text(), "parent": parent})
itemChild["parent"] = parent
itemMenu["children"].append(itemChild)
menu.append(itemMenu) menu.append(itemMenu)
for i in range(0, len(menu)-1): for i in range(0, len(children)-1):
self._logger.info("{0} Menu : {1}".format(self._name, menu[i])) self._logger.info("{0} : Child {1}".format(self._name, children[i]))
#for j in menu[i]["children"]: for j in range(0, len(menu)-1):
# if menu[i]["title"] == j["title"]: if menu[j]["title"] == children[i]["title"]:
# del menu[i] self._logger.info("{0} : Parent {1}".format(self._name, menu[j]))
del menu[j]
for j in range(0, len(menu)-1):
if menu[j]["title"] == children[i]["parent"]:
menu[j]["children"].append({"id":"", "title":children[i]["title"], "parent": children[i]["parent"]})
for i in menu:
self._logger.info("{0} : Menu {1}".format(self._name))