diff --git a/lib/WPImport.py b/lib/WPImport.py index 15d8f89..ff7ac92 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -225,56 +225,40 @@ class WPimport: id_comment = j["id"] 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) + page = page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, id_comment), auth=self._basic) except Exception as err: self._logger.error("Connection error : {0}".format(err)) exit(1) if page.status_code == 200: - self._logger.info("Comment updated for {0}".format(title)) + self._logger.info("Comment deleted for {0}".format(title)) else: - self._logger.error("Comment not updated for {0} due status code : {1}".format(title, page.status_code)) - else: - 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)) - self._logger.info(data) + self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code)) + + if i["parent_id"] != -1: + parent_id = int(i["parent_id"]) try: - page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data) + 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) - self._logger.info(page.status_code) - if page.status_code == 201: - self._logger.info("Comment added for {0}".format(title)) + 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("Comment not added for {0} due status code : {1}".format(title, page.status_code)) - self._logger.debug(page.content) + self._logger.error("Connection error with status code : {0}".format(page.status_code)) + try: + page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data) + except Exception as err: + self._logger.error("Connection error : {0}".format(err)) + exit(1) + if page.status_code == 201: + 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))