diff --git a/lib/WPImport.py b/lib/WPImport.py index 39b1228..48bc916 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -223,6 +223,25 @@ class WPimport: if page.status_code == 201: self._logger.info("Commentaire ajoute pour {0}".format(title)) + + def _getComment(self, comment): + comment_post = [] + for i in comment: + comment_div = find_all("div", class_="comment_item")[0] + comment_item = comment_div.text.split("\n") + footer = comment_div.find_all("div", class_="itemfooter") + comment_author = footer[0].text.split(",")[0].replace("Posté par ", "") + comment_date = footer[0].find_all("abbr")[0].get("title") + comment_content = "

" + for j in range(0, len(comment_item)-2): + if len(comment_item[j]) > 0: + comment_content = comment_content + comment_item[j] + "
" + comment_content = comment_content + "

" + parent = -1 + parent_class = "level-1" + + comment_post.append({"author": comment_author, "date": comment_date, "content": comment_content}) + return comment_post ## Add or Update post def _addOrUpdatePost(self, soup): @@ -250,7 +269,7 @@ class WPimport: articleacreator = soup.find_all("span", class_="articlecreator") dateheader = soup.find_all("div", class_="dateheader") itemfooter = soup.find_all("div", class_="itemfooter") - comment = soup.find_all("div", class_="comment_item") + comment = soup.find_all("li", class_="comment") img_a = articlebody[0].find_all("a", {"target": "_blank"}) list_img = [] for i in img_a: @@ -284,18 +303,8 @@ class WPimport: new_img["new_src"]=media["rendered"] list_img.append(new_img) - comment_post = [] - for i in comment: - comment_item = i.text.split("\n") - footer = i.find_all("div", class_="itemfooter") - comment_author = footer[0].text.split(",")[0].replace("Posté par ", "") - comment_date = footer[0].find_all("abbr")[0].get("title") - comment_content = "

" - for j in range(0, len(comment_item)-2): - if len(comment_item[j]) > 0: - comment_content = comment_content + comment_item[j] + "
" - comment_content = comment_content + "

" - comment_post.append({"author": comment_author, "date": comment_date, "content": comment_content}) + comment_post = self._getComment(comment) + a = itemfooter[0].find_all("a", {"rel": True}) for i in a: rel = i.get("rel")