Get level comment 50%

This commit is contained in:
Valentin CZERYBA 2023-04-16 19:16:23 +02:00
parent b54785c455
commit 0e15e88f31

View File

@ -223,7 +223,24 @@ class WPimport:
if page.status_code == 201: if page.status_code == 201:
self._logger.info("Commentaire ajoute pour {0}".format(title)) 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): def _getComment(self, comment):
comment_post = [] comment_post = []
for i in comment: for i in comment:
@ -239,8 +256,21 @@ class WPimport:
comment_content = comment_content + "</p>" comment_content = comment_content + "</p>"
parent = -1 parent = -1
parent_class = "level-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 return comment_post
## Add or Update post ## Add or Update post