From 84cc204007e6ac1222a8eaac15f24b996b7df7dd Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 18 Apr 2023 22:01:44 +0200 Subject: [PATCH] comment update/add in fixing --- lib/WPImport.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 8f853b1..15d8f89 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -14,7 +14,7 @@ class WPimport: self._logger = logger self._parser = parser self._headers_json = {'Content-Type': 'application/json', 'Accept':'application/json'} - + self._request = requests.Session() retries = Retry(total=10, @@ -223,8 +223,22 @@ class WPimport: if i["author"] == j["author_name"] and i["date"] == j["date"]: comment_exist = True id_comment = j["id"] - data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"]} + data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"} if comment_exist is True: + if i["parent_id"] != -1: + parent_id = int(i["parent_id"]) + try: + page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params) + except Exception as err: + self._logger.error("Connection error : {0}".format(err)) + exit(1) + if page.status_code == 200: + result = page.json() + for j in result: + if comment[parent_id]["author"] == j["author_name"] and comment[parent_id]["date"] == j["date"]: + data["parent"]=j["id"] + else: + self._logger.error("Connection error with status code : {0}".format(page.status_code)) try: page = page = self._request.post("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, id_comment), auth=self._basic, data=data) except Exception as err: @@ -260,6 +274,7 @@ class WPimport: self._logger.info("Comment added for {0}".format(title)) else: self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code)) + self._logger.debug(page.content) else: self._logger.error("Connection error with status code : {0}".format(page.status_code))