From be9ad9b934522c0a9647b7a13a45e15555054ec4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 13 Jul 2023 00:25:14 +0200 Subject: [PATCH] swap loop --- lib/WPMenu.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index 33178a9..a60fd44 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -78,23 +78,28 @@ class WPMenu: idMenu = 0 exist = False for i in ["categories", "tags"]: - if exist is False: - try: - params = {"search":title, "per_page":"100"} - 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: - idMenu = result[0]["id"] - exist = True - else: - self._logger.error("{0} : {2} didn't get due status code : {1}".format(self._name, page.status_code, i)) - 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, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), err)) - exit(1) - except Exception as err: - self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), err)) + for index in range(1,10): + if exist is False: + try: + params = {"search":title, "per_page":"100", "page":index} + 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: + idMenu = j["id"] + exist = True + + else: + self._logger.error("{0} : {2} didn't get due status code : {1}".format(self._name, page.status_code, i)) + 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, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), err)) + exit(1) + except Exception as err: + self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), err)) return idMenu def _menu(self, content):