get title from post
This commit is contained in:
parent
7593b68b6c
commit
82f9acd658
@ -74,9 +74,44 @@ class WPMenu:
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, canalblog, err))
|
self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, canalblog, err))
|
||||||
|
|
||||||
|
## replace caracter
|
||||||
|
|
||||||
|
def _replaceCaracter(self, title_rendered):
|
||||||
|
list_replace = {'’': "'", '–': '-', '…': '...', '« ': '"', ' »': '"', '« ': '"', ' »': '"', '’': "'", '"‘': "'"}
|
||||||
|
for old, new in list_replace.items():
|
||||||
|
title_rendered = title_rendered.replace(old, new)
|
||||||
|
return title_rendered
|
||||||
|
|
||||||
def _getIdfromTitlePost(self, content):
|
def _getIdfromTitlePost(self, content):
|
||||||
idMenu = 0
|
idMenu = 0
|
||||||
|
soup = BeautifulSoup(content, self._parser)
|
||||||
|
articletitle = soup.find("h2", class_="articletitle")
|
||||||
|
for index in range(0,10):
|
||||||
|
params = {"search":articletitle, "per_page":"100", "page":index}
|
||||||
|
try:
|
||||||
|
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()
|
||||||
|
self._logger.info("{0} : Get content post : {1}".format(self._name, len(result)))
|
||||||
|
for i in result:
|
||||||
|
title_rendered = i["name"]
|
||||||
|
if len(articletitle) != len(title_rendered):
|
||||||
|
title_rendered = self._replaceCaracter(title_rendered)
|
||||||
|
|
||||||
|
if articletitle == title_rendered:
|
||||||
|
idMenu = i["id"]
|
||||||
|
|
||||||
|
elif page.status_code == 400:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self._logger.error("{0} : Post 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, href, err))
|
||||||
|
exit(1)
|
||||||
|
except Exception as err:
|
||||||
|
self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, href, err))
|
||||||
|
|
||||||
return idMenu
|
return idMenu
|
||||||
|
|
||||||
def _getIdFromPost(self, href):
|
def _getIdFromPost(self, href):
|
||||||
@ -118,6 +153,7 @@ class WPMenu:
|
|||||||
self._logger.info("{0} link {1} title {2}".format(self._name, link, title))
|
self._logger.info("{0} link {1} title {2}".format(self._name, link, title))
|
||||||
if link == "index.html":
|
if link == "index.html":
|
||||||
idMenu = self._getId(title)
|
idMenu = self._getId(title)
|
||||||
|
|
||||||
return idMenu
|
return idMenu
|
||||||
|
|
||||||
def _getId(self, title):
|
def _getId(self, title):
|
||||||
@ -139,7 +175,8 @@ class WPMenu:
|
|||||||
self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i))
|
self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i))
|
||||||
idMenu = j["id"]
|
idMenu = j["id"]
|
||||||
exist = True
|
exist = True
|
||||||
|
elif page.status_code == 400:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} : {2} didn't get due status code : {1}".format(self._name, page.status_code, i))
|
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))
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user