From e17cace82072642032443571c03bc9658f0ffd17 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 24 Jul 2023 22:51:40 +0200 Subject: [PATCH] remove navigation --- lib/WPMenu.py | 60 +-------------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index 1345b67..0330641 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -260,65 +260,7 @@ class WPMenu: self._createMenu(menu) exit(0) - navigation = '' - for i in menu: - self._logger.info("{0} Menu parent {1} with id {2} and type {3} and link {4}".format(self._name, i["title"], i["id"], i["type"], i["link"])) - if len(i["children"]) > 0: - navigation = navigation + " \n\n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"]) - else: - navigation = navigation + " \n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"]) - for j in i["children"]: - navigation = navigation + " \n".replace("label-string", j["title"]).replace("id-string", str(j["id"])).replace("url-string", j["link"]).replace("kind-string", j["type"]) - - self._logger.info("{0} Menu children {1} with id {2} and type {3} and link {4}".format(self._name, j["title"], j["id"], j["type"], j["link"])) - if len(i["children"]) > 0: - navigation = navigation + " \n" - self._logger.info("{0} : {1}".format(self._name, navigation)) - - self._navigation(navigation) - - - def _navigation(self, content): - self._logger.info("{0} Get ID navigation from wordpress for {1}".format(self._name, self._wordpress)) - try: - title = "Menu {0}".format(self._wordpress) - exist = False - page = self._request_wordpress.get("{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), auth=self._basic) - if page.status_code == 200: - result = page.json() - self._logger.info("{0} : Get content navigation : {1}".format(self._name, len(result))) - for i in result: - self._logger.debug("{0} : Debug get item navigation : {1}".format(self._name, i)) - if i["title"]["rendered"] == title: - exist = True - self._logger.info("{0} : {1} is exist".format(self._name, title)) - if exist is False: - try: - self._logger.info("{0} Create navigation to wordpress for {1}".format(self._name, self._wordpress)) - data = {"title": title, "content": content} - page = self._request_wordpress.post("{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), auth=self._basic, headers=self._headers_json, data=json.dumps(data)) - if page.status_code == 201: - self._logger.info("{0} : Navigation Menu {1} is created".format(self._name, self._wordpress)) - self._logger.debug("{0} : Navigation Menu {1} create debug : ".format(self._name, page.content)) - - else: - self._logger.error("{0} : Post navigation didn't get due status code : {1}".format(self._name, page.status_code)) - self._logger.debug("{0} : {1}".format(self._name, page.content)) - except ConnectionError as err: - self._logger.error("{0} : Connection error for post naviguation url {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), err)) - exit(1) - except Exception as err: - self._logger.error("{0} : Exception error for post navigation url {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), err)) - - else: - self._logger.error("{0} : Get navigation didn't get due status code : {1}".format(self._name, page.status_code)) - self._logger.debug("{0} : {1}".format(self._name, page.content)) - except ConnectionError as err: - self._logger.error("{0} : Connection error for get url {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), err)) - exit(1) - except Exception as err: - self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/navigation".format(self._wordpress, self._protocol_wordpress), err)) - + def _createMenu(self, menu): title = "Menu {0}".format(self._wordpress) self._logger.info("{0} : Create menu from API Wordpress : {1}".format(self._name, title))