From 0e15e88f3174bd650d9b2ca83aaab0d6590f891e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 16 Apr 2023 19:16:23 +0200 Subject: [PATCH] Get level comment 50% --- lib/WPImport.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 48bc916..a39e42e 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -223,7 +223,24 @@ class WPimport: if page.status_code == 201: self._logger.info("Commentaire ajoute pour {0}".format(title)) + ## Check class name + + def _hasClassName(self, tag, className): + for i in tag["class"]: + if i == className: + return True + return False + ## Get class name + + def _getClassName(self, tag, className): + for i in tag["class"]: + if re.match(className, i): + return i + return "" + + ## Get all comments + def _getComment(self, comment): comment_post = [] for i in comment: @@ -239,8 +256,21 @@ class WPimport: comment_content = comment_content + "

" parent = -1 parent_class = "level-1" + if self._hasClassName(i, parent_class) is False: + block = False + className = self._getClassName(tag, "level-").split("-") + level = 1 + if len(className) > 0: + level = int(className[1]) + for j in range(i-1, 0): + if block is False: + levelName = "level-{0}".format(level - 1) + if self._hasClassName(comment[j], levelName): + parent = j + parent_class = levelName + block = True - comment_post.append({"author": comment_author, "date": comment_date, "content": comment_content}) + comment_post.append({"author": comment_author, "date": comment_date, "content": comment_content, "parent_id":parent, "parent_class": parent_class}) return comment_post ## Add or Update post