double comment

This commit is contained in:
Valentin CZERYBA 2023-04-20 00:08:56 +02:00
parent ca39826a11
commit c44ffc5a86

View File

@ -209,8 +209,7 @@ class WPimport:
def _addOrUpdateComment(self, post, comment, title):
for i in comment:
id_comment = []
comment_exist = False
try:
params = {"post": post, "author_name":i["author"], "date":i["date"]}
page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
@ -220,21 +219,21 @@ class WPimport:
if page.status_code == 200:
result = page.json()
for j in result:
comment_exist = True
id_comment.append(j["id"])
if comment_exist is True:
for j in id_comment:
try:
params = {"force":1}
page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j), params=params, auth=self._basic)
page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j["id"]), params=params, 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 deleted for {0}".format(title))
self._logger.debug("Comment deleted : {0}".format(i))
self._logger.debug("Comment deleted : {0}".format(j))
else:
self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code))
else:
self._logger.error("Comment not listed for {0} due status code : {1}".format(title, page.status_code))
for i in comment:
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"}
if i["parent_id"] != -1: