menu and sub-menu wip
This commit is contained in:
parent
74fa87ea73
commit
20c4adb3cf
@ -101,30 +101,34 @@ class WPMenu:
|
||||
soup = BeautifulSoup(content, self._parser)
|
||||
ul = soup.find("ul", id="listsmooth")
|
||||
menu = list()
|
||||
parents = list()
|
||||
children = list()
|
||||
for anchor in ul.find_all("li"):
|
||||
|
||||
parent = anchor.find("a").get_text().replace(" \xa0", "")
|
||||
itemMenu = {"id":"", "type":"", "title": parent, "parent": parent, "children":[]}
|
||||
itemChild = {"id":"", "type":"", "title": parent, "parent": parent}
|
||||
itemMenu = {"id":"", "type":"", "title": parent, "children":list()}
|
||||
|
||||
href = anchor.find("a").get("href")
|
||||
if href == self._wordpress:
|
||||
parent = "home"
|
||||
#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} Parent {1} : Child {2}".format(self._name, parent, a.get_text()))
|
||||
itemChild["title"] = a.get_text()
|
||||
itemChild["parent"] = parent
|
||||
itemMenu["children"].append(itemChild)
|
||||
children.append({"title": a.get_text(), "parent": parent})
|
||||
menu.append(itemMenu)
|
||||
|
||||
|
||||
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]
|
||||
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):
|
||||
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))
|
Loading…
x
Reference in New Issue
Block a user