comment update/add in fixing
This commit is contained in:
parent
edb9442b1c
commit
84cc204007
@ -14,7 +14,7 @@ class WPimport:
|
||||
self._logger = logger
|
||||
self._parser = parser
|
||||
self._headers_json = {'Content-Type': 'application/json', 'Accept':'application/json'}
|
||||
|
||||
|
||||
self._request = requests.Session()
|
||||
|
||||
retries = Retry(total=10,
|
||||
@ -223,8 +223,22 @@ class WPimport:
|
||||
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"], "status": "approved"}
|
||||
if comment_exist is True:
|
||||
if i["parent_id"] != -1:
|
||||
parent_id = int(i["parent_id"])
|
||||
try:
|
||||
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:
|
||||
if comment[parent_id]["author"] == j["author_name"] and comment[parent_id]["date"] == j["date"]:
|
||||
data["parent"]=j["id"]
|
||||
else:
|
||||
self._logger.error("Connection error with status code : {0}".format(page.status_code))
|
||||
try:
|
||||
page = page = self._request.post("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, id_comment), auth=self._basic, data=data)
|
||||
except Exception as err:
|
||||
@ -260,6 +274,7 @@ class WPimport:
|
||||
self._logger.info("Comment added for {0}".format(title))
|
||||
else:
|
||||
self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code))
|
||||
self._logger.debug(page.content)
|
||||
else:
|
||||
self._logger.error("Connection error with status code : {0}".format(page.status_code))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user