double comment
This commit is contained in:
parent
ca39826a11
commit
c44ffc5a86
@ -208,61 +208,60 @@ class WPimport:
|
|||||||
## Add or update comment
|
## Add or update comment
|
||||||
|
|
||||||
def _addOrUpdateComment(self, post, comment, title):
|
def _addOrUpdateComment(self, post, comment, title):
|
||||||
for i in comment:
|
for i in comment:
|
||||||
id_comment = []
|
|
||||||
comment_exist = False
|
|
||||||
try:
|
|
||||||
params = {"post": post, "author_name":i["author"], "date":i["date"]}
|
|
||||||
page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
|
|
||||||
except Exception as err:
|
|
||||||
self._logger.error("Connection error : {0}".format(err))
|
|
||||||
exit(1)
|
|
||||||
if page.status_code == 200:
|
|
||||||
result = page.json()
|
|
||||||
for j in result:
|
|
||||||
comment_exist = True
|
|
||||||
id_comment.append(j["id"])
|
|
||||||
if comment_exist is True:
|
|
||||||
for j in id_comment:
|
|
||||||
try:
|
|
||||||
params = {"force":1}
|
|
||||||
page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j), params=params, auth=self._basic)
|
|
||||||
except Exception as err:
|
|
||||||
self._logger.error("Connection error : {0}".format(err))
|
|
||||||
exit(1)
|
|
||||||
if page.status_code == 200:
|
|
||||||
self._logger.info("Comment deleted for {0}".format(title))
|
|
||||||
self._logger.debug("Comment deleted : {0}".format(i))
|
|
||||||
else:
|
|
||||||
self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code))
|
|
||||||
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"}
|
|
||||||
|
|
||||||
if i["parent_id"] != -1:
|
|
||||||
parent_id = int(i["parent_id"])
|
|
||||||
params = {"post": post, "author_name":comment[parent_id]["author"], "date":comment[parent_id]["date"]}
|
|
||||||
try:
|
try:
|
||||||
|
params = {"post": post, "author_name":i["author"], "date":i["date"]}
|
||||||
page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
|
page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._logger.error("Connection error : {0}".format(err))
|
self._logger.error("Connection error : {0}".format(err))
|
||||||
exit(1)
|
exit(1)
|
||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
result = page.json()
|
result = page.json()
|
||||||
if len(result) > 0:
|
for j in result:
|
||||||
data["parent"]=result[0]["id"]
|
try:
|
||||||
|
params = {"force":1}
|
||||||
|
page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j["id"]), params=params, auth=self._basic)
|
||||||
|
except Exception as err:
|
||||||
|
self._logger.error("Connection error : {0}".format(err))
|
||||||
|
exit(1)
|
||||||
|
if page.status_code == 200:
|
||||||
|
self._logger.info("Comment deleted for {0}".format(title))
|
||||||
|
self._logger.debug("Comment deleted : {0}".format(j))
|
||||||
|
else:
|
||||||
|
self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code))
|
||||||
else:
|
else:
|
||||||
self._logger.error("Connection error for parent comment with status code : {0}".format(page.status_code))
|
self._logger.error("Comment not listed for {0} due status code : {1}".format(title, page.status_code))
|
||||||
try:
|
|
||||||
page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
|
for i in comment:
|
||||||
except Exception as err:
|
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"}
|
||||||
self._logger.error("Connection error : {0}".format(err))
|
|
||||||
exit(1)
|
if i["parent_id"] != -1:
|
||||||
if page.status_code == 201:
|
parent_id = int(i["parent_id"])
|
||||||
self._logger.info("Comment added for {0}".format(title))
|
params = {"post": post, "author_name":comment[parent_id]["author"], "date":comment[parent_id]["date"]}
|
||||||
self._logger.debug("Data : {0}".format(data))
|
try:
|
||||||
else:
|
page = self._request.get("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, params=params)
|
||||||
self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code))
|
except Exception as err:
|
||||||
self._logger.debug(page.content)
|
self._logger.error("Connection error : {0}".format(err))
|
||||||
self._logger.debug("Data : {0}".format(data))
|
exit(1)
|
||||||
|
if page.status_code == 200:
|
||||||
|
result = page.json()
|
||||||
|
if len(result) > 0:
|
||||||
|
data["parent"]=result[0]["id"]
|
||||||
|
else:
|
||||||
|
self._logger.error("Connection error for parent comment with status code : {0}".format(page.status_code))
|
||||||
|
try:
|
||||||
|
page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
|
||||||
|
except Exception as err:
|
||||||
|
self._logger.error("Connection error : {0}".format(err))
|
||||||
|
exit(1)
|
||||||
|
if page.status_code == 201:
|
||||||
|
self._logger.info("Comment added for {0}".format(title))
|
||||||
|
self._logger.debug("Data : {0}".format(data))
|
||||||
|
else:
|
||||||
|
self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code))
|
||||||
|
self._logger.debug(page.content)
|
||||||
|
self._logger.debug("Data : {0}".format(data))
|
||||||
|
|
||||||
## Check class name
|
## Check class name
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user