diff --git a/lib/WPRemove.py b/lib/WPRemove.py index a876011..8b631ad 100644 --- a/lib/WPRemove.py +++ b/lib/WPRemove.py @@ -93,20 +93,29 @@ class WPRemove: result = r.json() if len(result) > 0: for i in result: - self._logger.info("{0} : Remove {2} for url {1} : {3}".format(self._name, self._wordpress, composant, i["title"]["rendered"])) - params = {"force":1} - try: - r = self._request.delete("{3}://{0}/wp-json/wp/v2/{1}/{2}".format(self._wordpress, composant, i["id"], self._protocol), auth=self._basic, headers=self._headers_json , params=params) - if r.status_code == 200: - self._logger.info("{0} : Post removed for URL {1} {2} : {3}".format(self._name, self._wordpress, composant, i["title"]["rendered"])) + is_delete = True + self._logger.info(i["slug"]) + if i["slug"] == "non-classe": + is_delete = False + if is_delete is True: + if composant == "tags" or composant == "categories": + title = i["name"] else: - self._logger.error("{0} : Connection error for post {1} {2} {3} with status code {4}".format(self._name, self._wordpress, composant, i["title"]["rendered"], r.status_code)) - except ConnectionError as err: - self._logger.error("{0} : Connection error for {1} remove : {2}".format(self._name, composant, err)) - exit(1) - except Exception as err: - self._logger.error("{0} : Exception error for {1} remove : {2}".format(self._name, composant, err)) - self._removeAll(composant) + title = i["title"]["rendered"] + self._logger.info("{0} : Remove {2} for url {1} : {3}".format(self._name, self._wordpress, composant, title)) + params = {"force":1} + try: + r = self._request.delete("{3}://{0}/wp-json/wp/v2/{1}/{2}".format(self._wordpress, composant, i["id"], self._protocol), auth=self._basic, headers=self._headers_json , params=params) + if r.status_code == 200: + self._logger.info("{0} : Post removed for URL {1} {2} : {3}".format(self._name, self._wordpress, composant, title)) + else: + self._logger.error("{0} : Connection error for post {1} {2} {3} with status code {4}".format(self._name, self._wordpress, composant, title, r.status_code)) + except ConnectionError as err: + self._logger.error("{0} : Connection error for {1} remove : {2}".format(self._name, composant, err)) + exit(1) + except Exception as err: + self._logger.error("{0} : Exception error for {1} remove : {2}".format(self._name, composant, err)) + self._removeAll(composant) if r.status_code == 400: self._logger.error("{0} : No content for {1} to remove : {2}".format(self._name, composant, r.status_code)) else: