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,56 +225,40 @@ class WPimport:
id_comment = j["id"] id_comment = j["id"]
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"} data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"}
if comment_exist is True: 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: 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: except Exception as err:
self._logger.error("Connection error : {0}".format(err)) self._logger.error("Connection error : {0}".format(err))
exit(1) exit(1)
if page.status_code == 200: if page.status_code == 200:
self._logger.info("Comment updated for {0}".format(title)) self._logger.info("Comment deleted for {0}".format(title))
else: else:
self._logger.error("Comment not updated for {0} due status code : {1}".format(title, page.status_code)) self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code))
else:
if i["parent_id"] != -1: if i["parent_id"] != -1:
parent_id = int(i["parent_id"]) 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: 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: except Exception as err:
self._logger.error("Connection error : {0}".format(err)) self._logger.error("Connection error : {0}".format(err))
exit(1) exit(1)
self._logger.info(page.status_code) if page.status_code == 200:
if page.status_code == 201: result = page.json()
self._logger.info("Comment added for {0}".format(title)) for j in result:
if comment[parent_id]["author"] == j["author_name"] and comment[parent_id]["date"] == j["date"]:
data["parent"]=j["id"]
else: else:
self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))
self._logger.debug(page.content) 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: else:
self._logger.error("Connection error with status code : {0}".format(page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))