update comment

This commit is contained in:
Valentin CZERYBA 2023-04-11 23:26:40 +02:00
parent a856311f04
commit 335266e1ad

View File

@ -144,12 +144,27 @@ class WPimport:
## Add or update comment
def _addOrUpdateComment(self, post, comment):
for i in comment:
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"]}
page = requests.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
if page.status_code == 201:
self._logger.info("Commentaire ajoute pour {0}".format(result["title"]["raw"]))
def _addOrUpdateComment(self, post, comment, title):
params = {"post": post}
block = True
page = requests.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
if page.status_code == 200:
result = page.json()
for i in comment:
comment_exist = False
for j in result:
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"]}
if comment_exist is True:
page = page = requests.post("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, id_comment), auth=self._basic, data=data)
if page.status_code == 200:
self._logger.info("Commentaire mise à jour pour {0}".format(title))
else:
page = requests.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
if page.status_code == 201:
self._logger.info("Commentaire ajoute pour {0}".format(title))
## Add or Update post
@ -273,6 +288,7 @@ class WPimport:
if page.status_code == 200:
result = page.json()
self._logger.info("Article mis à jour : {0}".format(result["title"]["raw"]))
self._addOrUpdateComment(result["id"], comment_post, result["title"]["raw"])
self._linkImgPost(result["title"]["raw"], list_img, result["id"])
@ -282,5 +298,5 @@ class WPimport:
if page.status_code == 201:
result = page.json()
self._logger.info("Article ajoute : {0}".format(result["title"]["raw"]))
self._addOrUpdateComment(result["id"], comment_post)
self._addOrUpdateComment(result["id"], comment_post, result["title"]["raw"])
self._linkImgPost(result["title"]["raw"], list_img, result["id"])