list menu wip

This commit is contained in:
Valentin CZERYBA 2023-07-09 19:11:05 +02:00
parent 03f833a2c3
commit 74fa87ea73

View File

@ -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))
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]