From 41e192f903381c805b1ebd097cea994c11f64034 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 11 Sep 2023 22:40:41 +0200 Subject: [PATCH 1/9] fix bug import --- lib/WPImport.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index d0240a9..c27c22d 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -302,7 +302,7 @@ class WPimport: exit(1) except Exception as err: self._logger.error("{0} : Exception error for update page : {1}".format(self._name, err)) - if page.status_code == 400: + elif page.status_code == 400: self._logger.error("{0} : Connection for update post unauthorized : {1}".format(self._name, page.status_code)) self._logger.debug("{0} : {1}".format(self._name, page.content)) break @@ -817,7 +817,7 @@ class WPimport: listelement[i].append(k["id"]) else: break - if page.status_code == 400: + elif page.status_code == 400: self._logger.error("{0} : {1} not found due status code : {2}".format(self._name, i, page.status_code)) self._logger.debug("{0} : {1}".format(self._name, page.content)) break @@ -867,12 +867,15 @@ class WPimport: bodyhtml = bodyhtml.replace(i["old_href"], o.path) bodyhtml = bodyhtml.replace(i["old_src"], o.path) hour = articledate[0].text - time = dateheader[0].text.split(" ") + time = "" + if len(dateheader) > 0: + time = dateheader[0].text.split(" ") self._logger.debug("{0} : Title post : |{1}|".format(self._name, title)) title = self._removeSpace(title) self._logger.debug("{0} : Rendered Title post : |{1}|".format(self._name, title)) - - data = {"title":title, "content":bodyhtml, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]} + data = {"title":title, "content":bodyhtml, "status":"publish", "tags": listelement["tags"], "categories": listelement["categories"]} + if len(dateheader) > 0: + data = {"title":title, "content":bodyhtml, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]} self._logger.debug("{0} : Data for post : |{1}| : {2}" .format(self._name, title, data)) data["author"] = self._getAuthor(author) From dbab60c7dc266ed33e9791196d24505ce8dca69b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 11 Sep 2023 23:20:22 +0200 Subject: [PATCH 2/9] fix import album --- lib/WPImport.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index c27c22d..2740011 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -141,7 +141,7 @@ class WPimport: def _getInfoAlbum(self, link): if self._ssl_canalblog: - link = link.replace("http", "https") + link = link.replace("http", "https").("httpss", "https") self._logger.info("{0} : Info album : {1}".format(self._name, link)) link_o = urlparse(link) if len(link_o.netloc) > 0: @@ -162,14 +162,16 @@ class WPimport: if os.path.exists("{0}/..{1}".format(self._directory, link_o)): page_img = open("{0}/..{1}".format(self._directory, link_o), "r") soup = BeautifulSoup(page_img, self._parser) - paragraph = soup.find("div", class_="albumbody").find("p") - self._logger.info("{0} get paragraph : {1}".format(self._name, paragraph)) - split_paragraph = str(paragraph).split("
") - self._logger.info("{0} length paragraph splitted : {1}".format(self._name, len(split_paragraph))) - if len(split_paragraph) == 1: - split_paragraph = str(paragraph).split("
") - self._logger.info("{0} get paragraph splitted : {1}".format(self._name, split_paragraph)) - author = split_paragraph[1].split(":")[1].replace(" ", "").lower() + paragraphs = soup.find("div", class_="albumbody").find_all("p") + for paragraph in paragraphs: + self._logger.info("{0} get paragraph : {1}".format(self._name, paragraph)) + split_paragraph = str(paragraph).split("
") + self._logger.info("{0} length paragraph splitted : {1}".format(self._name, len(split_paragraph))) + if len(split_paragraph) == 1: + split_paragraph = str(paragraph).split("
") + self._logger.info("{0} get paragraph splitted : {1}".format(self._name, split_paragraph)) + if len(split_paragraph) > 0: + author = split_paragraph[1].split(":")[1].replace(" ", "").lower() return author From 6f78a48e57b3744abd9c2559f689486aa5e2d2c3 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 11 Sep 2023 23:20:48 +0200 Subject: [PATCH 3/9] fix index --- lib/WPImport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 2740011..d6696e5 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -170,7 +170,7 @@ class WPimport: if len(split_paragraph) == 1: split_paragraph = str(paragraph).split("
") self._logger.info("{0} get paragraph splitted : {1}".format(self._name, split_paragraph)) - if len(split_paragraph) > 0: + if len(split_paragraph) > 1: author = split_paragraph[1].split(":")[1].replace(" ", "").lower() return author From 0c94783852fb9da827c808b9721904ac8b4254e7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 14 Sep 2023 21:23:27 +0200 Subject: [PATCH 4/9] fix album author --- lib/WPImport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index d6696e5..f48bc85 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -171,7 +171,8 @@ class WPimport: split_paragraph = str(paragraph).split("
") self._logger.info("{0} get paragraph splitted : {1}".format(self._name, split_paragraph)) if len(split_paragraph) > 1: - author = split_paragraph[1].split(":")[1].replace(" ", "").lower() + if len(split_paragraph[1].split(":")) > 1: + author = split_paragraph[1].split(":")[1].replace(" ", "").lower() return author From bce1643135cba77de5b9e46eecd46c064fb35481 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 14 Sep 2023 21:27:09 +0200 Subject: [PATCH 5/9] fix replace --- lib/WPImport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index f48bc85..8c2aa2d 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -141,7 +141,7 @@ class WPimport: def _getInfoAlbum(self, link): if self._ssl_canalblog: - link = link.replace("http", "https").("httpss", "https") + link = link.replace("http", "https").replace("httpss", "https") self._logger.info("{0} : Info album : {1}".format(self._name, link)) link_o = urlparse(link) if len(link_o.netloc) > 0: From d2cfb949f869d81d551224d04947a003cd5ff8d2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Sep 2023 23:11:25 +0200 Subject: [PATCH 6/9] add image for featured image --- lib/WPImport.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/WPImport.py b/lib/WPImport.py index 8c2aa2d..3b4131b 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -461,6 +461,19 @@ class WPimport: self._logger.error("{0} : Exception error for post media featured : {1}".format(self._name, err)) else: self._logger.info("{0} : No media found for {1}".format(self._name, h2)) + try: + page = self._request.get(img_src.replace("_q", "")) + if page.status_code == 200: + self._logger.info("{0} : Get image for media featured : {1}".format(self._name, r.json()["title"]["raw"])) + self._addOrUpdateMedia(img_src.replace("_q", ""), page.content) + else: + self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code)) + self._logger.debug("{0} : {1}".format(self._name, r.content)) + except ConnectionError as err: + self._logger.error("{0} : Connection error for get to image for featured media : {1}".format(self._name, err)) + exit(1) + except Exception as err: + self._logger.error("{0} : Exception error for get to image media featured : {1}".format(self._name, err)) else: self._logger.error("{0} : Connection error with status code for search featured media: {1}".format(self._name, page.status_code)) self._logger.debug("{0} : {1}".format(self._name, page.content)) From 0e5afe60a7794c1c8e9091476dbcb46485664806 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Sep 2023 23:13:08 +0200 Subject: [PATCH 7/9] add image featured media --- lib/WPImport.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/WPImport.py b/lib/WPImport.py index 3b4131b..3d09a02 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -466,6 +466,7 @@ class WPimport: if page.status_code == 200: self._logger.info("{0} : Get image for media featured : {1}".format(self._name, r.json()["title"]["raw"])) self._addOrUpdateMedia(img_src.replace("_q", ""), page.content) + self._addOrUpdateFeaturedMedia(soup) else: self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code)) self._logger.debug("{0} : {1}".format(self._name, r.content)) From fa1854052bafb1cee93591b58e55e6773c4d1dd4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Sep 2023 23:14:24 +0200 Subject: [PATCH 8/9] fix if --- lib/WPImport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 3d09a02..5ad9416 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -467,7 +467,7 @@ class WPimport: self._logger.info("{0} : Get image for media featured : {1}".format(self._name, r.json()["title"]["raw"])) self._addOrUpdateMedia(img_src.replace("_q", ""), page.content) self._addOrUpdateFeaturedMedia(soup) - else: + else: self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code)) self._logger.debug("{0} : {1}".format(self._name, r.content)) except ConnectionError as err: From c275f10fb08c8050a5f16efe01e1736d45006159 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Sep 2023 23:38:35 +0200 Subject: [PATCH 9/9] test ok for featured media --- lib/WPImport.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 5ad9416..118c102 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -464,12 +464,13 @@ class WPimport: try: page = self._request.get(img_src.replace("_q", "")) if page.status_code == 200: - self._logger.info("{0} : Get image for media featured : {1}".format(self._name, r.json()["title"]["raw"])) - self._addOrUpdateMedia(img_src.replace("_q", ""), page.content) - self._addOrUpdateFeaturedMedia(soup) + self._logger.info("{0} : Get image for media featured : {1}".format(self._name, img_src.replace("_q", ""))) + media = self._addOrUpdateMedia(img_src.replace("_q", ""), page) + if media["id"] != "": + self._addOrUpdateFeaturedMedia(soup) else: self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code)) - self._logger.debug("{0} : {1}".format(self._name, r.content)) + self._logger.debug("{0} : {1}".format(self._name, page.content)) except ConnectionError as err: self._logger.error("{0} : Connection error for get to image for featured media : {1}".format(self._name, err)) exit(1)