update comment
This commit is contained in:
parent
a856311f04
commit
335266e1ad
@ -144,12 +144,27 @@ class WPimport:
|
|||||||
|
|
||||||
## Add or update comment
|
## Add or update comment
|
||||||
|
|
||||||
def _addOrUpdateComment(self, post, comment):
|
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:
|
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"]}
|
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)
|
page = requests.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
|
||||||
if page.status_code == 201:
|
if page.status_code == 201:
|
||||||
self._logger.info("Commentaire ajoute pour {0}".format(result["title"]["raw"]))
|
self._logger.info("Commentaire ajoute pour {0}".format(title))
|
||||||
|
|
||||||
## Add or Update post
|
## Add or Update post
|
||||||
|
|
||||||
@ -273,6 +288,7 @@ class WPimport:
|
|||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
result = page.json()
|
result = page.json()
|
||||||
self._logger.info("Article mis à jour : {0}".format(result["title"]["raw"]))
|
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"])
|
self._linkImgPost(result["title"]["raw"], list_img, result["id"])
|
||||||
|
|
||||||
|
|
||||||
@ -282,5 +298,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"]))
|
||||||
self._addOrUpdateComment(result["id"], comment_post)
|
self._addOrUpdateComment(result["id"], comment_post, result["title"]["raw"])
|
||||||
self._linkImgPost(result["title"]["raw"], list_img, result["id"])
|
self._linkImgPost(result["title"]["raw"], list_img, result["id"])
|
Loading…
x
Reference in New Issue
Block a user