diff --git a/lib/WPMenu.py b/lib/WPMenu.py index a60fd44..fc7d8dd 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -82,13 +82,15 @@ class WPMenu: if exist is False: try: params = {"search":title, "per_page":"100", "page":index} + self._logger.info("{0} Get menu {1} {2} {3}".format(self._name, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), index, title)) page = self._request_wordpress.get("{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), auth=self._basic, params=params) if page.status_code == 200: result = page.json() if len(result) > 0: for j in result: - self._logger.info("{0} info : {1} {2}".format(self._name, j["name"], title)) - if j["name"] == title: + self._logger.info("{0} info : {1} {2} {3}".format(self._name, j["name"], j["slug"], title)) + if j["name"] == title or j["slug"] == title: + self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i)) idMenu = j["id"] exist = True @@ -114,13 +116,14 @@ 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()} + itemMenu = {"id":"", "type":"", "title": parent, "href":href, "children":list()} if href == "#": li = anchor.find("ul").find_all("li") for child in li: a = child.find("a") + href = a.get("href") self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text())) - children.append({"title": a.get_text(), "parent": parent}) + children.append({"title": a.get_text(), "parent": parent, "href":href}) menu.append(itemMenu) @@ -142,6 +145,15 @@ class WPMenu: if menu[i]["title"] != "home": for j in range(0, len(menu[i]["children"])): idMenu = self._getId(menu[i]["children"][j]["title"]) + if idMenu == 0: + title = href[::-1] + link = title.split("/")[0] + link = link[::-1] + title = title.split("/")[1] + title = title[::-1] + self._logger.info("{0} link {1} title {2}".format(self._name, link, title)) + if link == "index.html": + idMenu = self._getId(title) if idMenu != 0: menu[i]["children"][j] = {"id":idMenu, "title": menu[i]["children"][j]["title"], "parent": menu[i]["children"][j]["parent"]} idMenu = self._getId(menu[i]["title"])