From a856311f044ce6ab3fd69d887ffdb6540373c25b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 11 Apr 2023 22:30:00 +0200 Subject: [PATCH] add method for comment --- lib/WPImport.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 9e2cec6..f5d68cb 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -141,6 +141,15 @@ class WPimport: media["id"] = res["id"] 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 @@ -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"]) \ No newline at end of file