add menu WIP debug
This commit is contained in:
parent
1f8ea70b40
commit
72fbe0a364
@ -272,4 +272,44 @@ class WPMenu:
|
||||
if len(i["children"]) > 0:
|
||||
navigation = navigation + "<!-- /wp:navigation-submenu --> \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:
|
||||
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": "Menu {0}".format(self._wordpress), "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))
|
||||
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))
|
Loading…
x
Reference in New Issue
Block a user