swap loop
This commit is contained in:
parent
e6328135da
commit
be9ad9b934
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user