Compare commits

...

2 Commits

Author SHA1 Message Date
5059a15826 menu and submenu 2023-07-11 00:17:24 +02:00
20c4adb3cf menu and sub-menu wip 2023-07-09 21:42:09 +02:00

View File

@ -56,6 +56,7 @@ class WPMenu:
## Get from URL ## Get from URL
def fromUrl(self, canalblog): def fromUrl(self, canalblog):
self._canalblog = canalblog
try: try:
o = urlparse(canalblog) o = urlparse(canalblog)
o = o._replace(scheme=self._protocol_canalblog) o = o._replace(scheme=self._protocol_canalblog)
@ -101,30 +102,35 @@ 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":[]}
itemChild = {"id":"", "type":"", "title": parent, "parent": parent}
href = anchor.find("a").get("href") 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) #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} {2}".format(self._name, i["title"], len(i["children"])))