add search tags and categories before create tags and categories
This commit is contained in:
parent
d64aed6240
commit
edb9442b1c
@ -14,7 +14,7 @@ class WPimport:
|
|||||||
self._logger = logger
|
self._logger = logger
|
||||||
self._parser = parser
|
self._parser = parser
|
||||||
self._headers_json = {'Content-Type': 'application/json', 'Accept':'application/json'}
|
self._headers_json = {'Content-Type': 'application/json', 'Accept':'application/json'}
|
||||||
|
|
||||||
self._request = requests.Session()
|
self._request = requests.Session()
|
||||||
|
|
||||||
retries = Retry(total=10,
|
retries = Retry(total=10,
|
||||||
@ -321,17 +321,8 @@ class WPimport:
|
|||||||
listelement = {}
|
listelement = {}
|
||||||
|
|
||||||
for i in liste:
|
for i in liste:
|
||||||
try:
|
element[i] = []
|
||||||
page = self._request.get("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress,i))
|
listelement[i] = []
|
||||||
except Exception as err:
|
|
||||||
self._logger.error("Connection error : {0}".format(err))
|
|
||||||
exit(1)
|
|
||||||
if page.status_code == 200:
|
|
||||||
elements[i] = page.json()
|
|
||||||
element[i] = []
|
|
||||||
listelement[i] = []
|
|
||||||
else:
|
|
||||||
self._logger.error("Connection error with status code : {0}".format(page.status_code))
|
|
||||||
|
|
||||||
articletitle = soup.find_all("h2", class_="articletitle")
|
articletitle = soup.find_all("h2", class_="articletitle")
|
||||||
articlebody = soup.find_all("div", class_="articlebody")
|
articlebody = soup.find_all("div", class_="articlebody")
|
||||||
@ -390,13 +381,25 @@ class WPimport:
|
|||||||
for i in liste:
|
for i in liste:
|
||||||
for j in element[i]:
|
for j in element[i]:
|
||||||
element_exist = False
|
element_exist = False
|
||||||
for k in elements[i]:
|
try:
|
||||||
if k["name"] == j:
|
params = {"params":j}
|
||||||
element_exist = True
|
page = self._request.get("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i), auth=self._basic, params=params)
|
||||||
listelement[i].append(k["id"])
|
except Exception as err:
|
||||||
|
self._logger.error("Connection error : {0}".format(err))
|
||||||
|
exit(1)
|
||||||
|
if page.status_code == 200:
|
||||||
|
element_exist = True
|
||||||
|
result = page.json()
|
||||||
|
listelement[i].append(result[0]["id"])
|
||||||
|
|
||||||
|
else:
|
||||||
|
self._logger.error("{0} not finded due status code : {1}".format(i, page.status_code))
|
||||||
|
|
||||||
if element_exist is False:
|
if element_exist is False:
|
||||||
data = {"name": j}
|
data = {"name": j}
|
||||||
self._logger.debug("URL : {0} with data : {1} and with headers : {2}".format("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i), data, self._headers_json))
|
self._logger.debug("URL : {0} ".format("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i)))
|
||||||
|
self._logger.debug("data : {0}".format(data))
|
||||||
|
self._logger.debug("headers : {0}".format(self._headers_form))
|
||||||
try:
|
try:
|
||||||
page = self._request.post("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i), auth=self._basic, headers=self._headers_json, data=data)
|
page = self._request.post("http://{0}/wp-json/wp/v2/{1}".format(self._wordpress, i), auth=self._basic, headers=self._headers_json, data=data)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -407,7 +410,7 @@ class WPimport:
|
|||||||
listelement[i].append(result["id"])
|
listelement[i].append(result["id"])
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} not added due status code : {1}".format(i, page.status_code))
|
self._logger.error("{0} not added due status code : {1}".format(i, page.status_code))
|
||||||
|
self._logger.debug(listelement)
|
||||||
title = articletitle[0].text
|
title = articletitle[0].text
|
||||||
author = articleacreator[0].text.lower()
|
author = articleacreator[0].text.lower()
|
||||||
body = articlebody[0].find_all("p")
|
body = articlebody[0].find_all("p")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user