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

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