From d3ec7d147d0476e9d26ea5ff76830624037579c6 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 23 May 2023 11:22:37 +0200 Subject: [PATCH] loop replace --- lib/WPImport.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index dbffb0f..bf04c98 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -506,6 +506,8 @@ class WPimport: self._logger.debug("{0} : {1}".format(page.content)) if title[len(title)-1] == " ": title = title[:-1] + if title[0] == " ": + title = title[1:] page_is_exist = False for index in range(1,10): @@ -531,14 +533,10 @@ class WPimport: if len(i["title"]["rendered"]) == len(title): title_rendered = i["title"]["rendered"] else: - title_rendered = i["title"]["rendered"].replace('’', "'") - title_rendered = title_rendered.replace('–', '-') - title_rendered = title_rendered.replace('…', '...') - title_rendered = title_rendered.replace('« ', '"') - title_rendered = title_rendered.replace(' »', '"') - title_rendered = title_rendered.replace('« ', '"') - title_rendered = title_rendered.replace(' »', '"') - title_rendered = title_rendered.replace('’', "'") + title_rendered = i["title"]["rendered"] + list_replace = {'’': "'", '–': '-', '…': '...', '« ': '"', ' »': '"', '« ': '"', ' »': '"', '’': "'", '"‘': "'"} + for old, new in list_replace.items(): + title_rendered = title_rendered.replace(old, new) 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: