replace post by delete

This commit is contained in:
Valentin CZERYBA 2023-04-19 22:21:15 +02:00
parent 84cc204007
commit 1c252c9a14

View File

@ -225,6 +225,16 @@ 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:
try:
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 deleted for {0}".format(title))
else:
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:
@ -239,37 +249,11 @@ class WPimport:
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:
self._logger.error("Connection error : {0}".format(err))
exit(1)
if page.status_code == 200:
self._logger.info("Comment updated 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)
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)
self._logger.info(page.status_code)
if page.status_code == 201:
self._logger.info("Comment added for {0}".format(title))
else: