fix get id menu
This commit is contained in:
parent
be9ad9b934
commit
0445054dc8
@ -82,13 +82,15 @@ class WPMenu:
|
|||||||
if exist is False:
|
if exist is False:
|
||||||
try:
|
try:
|
||||||
params = {"search":title, "per_page":"100", "page":index}
|
params = {"search":title, "per_page":"100", "page":index}
|
||||||
|
self._logger.info("{0} Get menu {1} {2} {3}".format(self._name, "{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), index, title))
|
||||||
page = self._request_wordpress.get("{2}://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i, self._protocol_wordpress), auth=self._basic, params=params)
|
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:
|
if page.status_code == 200:
|
||||||
result = page.json()
|
result = page.json()
|
||||||
if len(result) > 0:
|
if len(result) > 0:
|
||||||
for j in result:
|
for j in result:
|
||||||
self._logger.info("{0} info : {1} {2}".format(self._name, j["name"], title))
|
self._logger.info("{0} info : {1} {2} {3}".format(self._name, j["name"], j["slug"], title))
|
||||||
if j["name"] == title:
|
if j["name"] == title or j["slug"] == title:
|
||||||
|
self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i))
|
||||||
idMenu = j["id"]
|
idMenu = j["id"]
|
||||||
exist = True
|
exist = True
|
||||||
|
|
||||||
@ -114,13 +116,14 @@ class WPMenu:
|
|||||||
href = anchor.find("a").get("href")
|
href = anchor.find("a").get("href")
|
||||||
if href == "{0}://{1}/".format(self._protocol_canalblog, self._canalblog):
|
if href == "{0}://{1}/".format(self._protocol_canalblog, self._canalblog):
|
||||||
parent = "home"
|
parent = "home"
|
||||||
itemMenu = {"id":"", "type":"", "title": parent, "children":list()}
|
itemMenu = {"id":"", "type":"", "title": parent, "href":href, "children":list()}
|
||||||
if href == "#":
|
if href == "#":
|
||||||
li = anchor.find("ul").find_all("li")
|
li = anchor.find("ul").find_all("li")
|
||||||
for child in li:
|
for child in li:
|
||||||
a = child.find("a")
|
a = child.find("a")
|
||||||
|
href = a.get("href")
|
||||||
self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text()))
|
self._logger.info("{0} Parent {1} : Child {2}".format(self._name, parent, a.get_text()))
|
||||||
children.append({"title": a.get_text(), "parent": parent})
|
children.append({"title": a.get_text(), "parent": parent, "href":href})
|
||||||
menu.append(itemMenu)
|
menu.append(itemMenu)
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +145,15 @@ class WPMenu:
|
|||||||
if menu[i]["title"] != "home":
|
if menu[i]["title"] != "home":
|
||||||
for j in range(0, len(menu[i]["children"])):
|
for j in range(0, len(menu[i]["children"])):
|
||||||
idMenu = self._getId(menu[i]["children"][j]["title"])
|
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)
|
||||||
if idMenu != 0:
|
if idMenu != 0:
|
||||||
menu[i]["children"][j] = {"id":idMenu, "title": menu[i]["children"][j]["title"], "parent": menu[i]["children"][j]["parent"]}
|
menu[i]["children"][j] = {"id":idMenu, "title": menu[i]["children"][j]["title"], "parent": menu[i]["children"][j]["parent"]}
|
||||||
idMenu = self._getId(menu[i]["title"])
|
idMenu = self._getId(menu[i]["title"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user