add method for comment

This commit is contained in:
Valentin CZERYBA 2023-04-11 22:30:00 +02:00
parent 7848968fa1
commit a856311f04

View File

@ -141,6 +141,15 @@ class WPimport:
media["id"] = res["id"] media["id"] = res["id"]
media["rendered"] = res["guid"]["rendered"] media["rendered"] = res["guid"]["rendered"]
return media return media
## 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"]))
## Add or Update post ## Add or Update post
@ -273,9 +282,5 @@ class WPimport:
if page.status_code == 201: if page.status_code == 201:
result = page.json() result = page.json()
self._logger.info("Article ajoute : {0}".format(result["title"]["raw"])) self._logger.info("Article ajoute : {0}".format(result["title"]["raw"]))
for i in comment_post: self._addOrUpdateComment(result["id"], comment_post)
data = {"post": result["id"], "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"]))
self._linkImgPost(result["title"]["raw"], list_img, result["id"]) self._linkImgPost(result["title"]["raw"], list_img, result["id"])