From 5fe4b1f7869f4c230026c914262721f192f5fdc8 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 13 Jul 2023 23:53:54 +0200 Subject: [PATCH] add href --- lib/WPMenu.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index fc7d8dd..aae2864 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -72,7 +72,25 @@ class WPMenu: self._logger.error("{0} : Connection error for get url {1} : {2}".format(self._name, canalblog, err)) exit(1) except Exception as err: - self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, canalblog, err)) + self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, canalblog, err)) + + def _getIdFromPost(self, href): + idMenu = 0 + return idMenu + + def _getIdFromReverse(self, title, href): + self._logger.info("{0} : get title {1} from href {2}".format(self._name, title, href)) + idMenu = 0 + if href != "#": + 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) + return idMenu def _getId(self, title): idMenu = 0 @@ -138,7 +156,7 @@ class WPMenu: for j in range(0, len(menu)): self._logger.info("{0} : Children for : {1}".format(self._name, menu[j]["title"])) if menu[j]["title"] == children[i]["parent"]: - menu[j]["children"].append({"id":"", "title":children[i]["title"], "parent": children[i]["parent"]}) + menu[j]["children"].append({"id":"", "title":children[i]["title"], "parent": children[i]["parent"], "href":children[i]["href"]}) for i in range(0, len(menu)): self._logger.info("{0} : Menu {1} {2}".format(self._name, menu[i]["title"], len(menu[i]["children"]))) @@ -146,17 +164,14 @@ class WPMenu: 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) + self._logger.debug("{0} : content children {1}".format(self._name, menu[i]["children"][j])) + idMenu = self._getIdFromReverse(menu[i]["children"][j]["title"], menu[i]["children"][j]["href"]) 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"]) + self._logger.debug("{0} : content parent {1}".format(self._name, menu[i])) + if idMenu == 0: + idMenu = self._getIdFromReverse(menu[i]["title"], menu[i]["href"]) if idMenu != 0: menu[i] = {"id":idMenu, "title":menu[i]["title"], "children": menu[i]["children"]}