Skip to content
Snippets Groups Projects
Commit 1534b601 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Comments ar now saved as HTML instead of text

parent b762c48a
No related branches found
No related tags found
No related merge requests found
import re import re
from pprint import pprint from pprint import pprint
from typing import List from typing import Any, List
from lxml import html from lxml import html
from rdflib import Graph, Literal from rdflib import Graph, Literal
...@@ -12,7 +12,8 @@ class Comment: ...@@ -12,7 +12,8 @@ class Comment:
id: str id: str
num: int num: int
text: str text: str
html: str html: Any
elem: Any
def __repr__(self): def __repr__(self):
return str(self.__dict__) return str(self.__dict__)
...@@ -49,7 +50,8 @@ def parse_page(graph: Graph, filepath: str, id: str): ...@@ -49,7 +50,8 @@ def parse_page(graph: Graph, filepath: str, id: str):
for cmt_div in zi: for cmt_div in zi:
comment = Comment() comment = Comment()
comment.text = cmt_div.text_content() comment.text = cmt_div.text_content()
comment.html = cmt_div comment.html = html.tostring(cmt_div, encoding="unicode")
comment.elem = cmt_div
comment.id = cmt_div.get("id") comment.id = cmt_div.get("id")
# Split id in two parts (non-digits and digits), then match on these parts # Split id in two parts (non-digits and digits), then match on these parts
m = regex_comment.match(comment.id) m = regex_comment.match(comment.id)
...@@ -59,16 +61,16 @@ def parse_page(graph: Graph, filepath: str, id: str): ...@@ -59,16 +61,16 @@ def parse_page(graph: Graph, filepath: str, id: str):
print(f"Comment, num={num}") print(f"Comment, num={num}")
comment.num = int(num) comment.num = int(num)
page.comments_misc.append(comment) page.comments_misc.append(comment)
graph.add((NS[id], NS["commentaireInfo"], Literal(comment.text))) graph.add((NS[id], NS["commentaireInfo"], Literal(comment.html)))
case ["divSugg", num]: case ["divSugg", num]:
print(f"Suggestion, num={num}") print(f"Suggestion, num={num}")
comment.num = int(num) comment.num = int(num)
page.comments_sugg.append(comment) page.comments_sugg.append(comment)
graph.add((NS[id], NS["commentaireSugg"], Literal(comment.text))) graph.add((NS[id], NS["commentaireSugg"], Literal(comment.html)))
case ["divCmtSucces", _]: case ["divCmtSucces", _]:
print(f"Succès") print(f"Succès")
page.comment_success = comment page.comment_success = comment
graph.add((NS[id], NS["commentaireSucces"], Literal(comment.text))) graph.add((NS[id], NS["commentaireSucces"], Literal(comment.html)))
case [other, _]: case [other, _]:
print(f"other: {other}") print(f"other: {other}")
pprint(page) pprint(page)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment