reduce line code and add private method

This commit is contained in:
Valentin CZERYBA 2023-05-23 13:45:59 +02:00
parent d3ec7d147d
commit f69298179a

View File

@ -90,6 +90,23 @@ class WPimport:
# Private method
## 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
## remove space
def _removeSpace(self, title):
if title[len(title)-1] == " ":
title = title[:-1]
if title[0] == " ":
title = title[1:]
return title
## Get all files
def _getFiles(self, item):
@ -504,10 +521,7 @@ class WPimport:
else:
self._logger.error("{0} : Connection error with status code for get author : {1}".format(self._name, page.status_code))
self._logger.debug("{0} : {1}".format(page.content))
if title[len(title)-1] == " ":
title = title[:-1]
if title[0] == " ":
title = title[1:]
title = self._removeSpace(title)
page_is_exist = False
for index in range(1,10):
@ -529,14 +543,10 @@ class WPimport:
self._logger.info("{0} : Number result posts : {1}".format(self._name, len(result)))
count = 0
for i in result:
self._logger.info("{0} : Search title posts for |{2}| : |{1}|".format(self._name, i["title"]["rendered"], title))
if len(i["title"]["rendered"]) == len(title):
title_rendered = i["title"]["rendered"]
else:
title_rendered = i["title"]["rendered"]
list_replace = {'’': "'", '–': '-', '…': '...', '« ': '"', ' »': '"', '« ': '"', ' »': '"', '’': "'", '"‘': "'"}
for old, new in list_replace.items():
title_rendered = title_rendered.replace(old, new)
self._logger.info("{0} : Search title posts for |{2}| : |{1}|".format(self._name, title_rendered, title))
if len(title_rendered) != len(title):
title_rendered = self._replaceCaracter(title_rendered)
self._logger.debug("{0} : Search title posts for |{2}| : |{1}|".format(self._name, title_rendered, title))
self._logger.debug("{0} : SIze of title : {1} - {2}".format(self._name, len(title), len(title_rendered)))
if title_rendered == title: