ai_dataset/main_qa_data/json2html.py

78 lines
1.7 KiB
Python
Raw Normal View History

2024-09-17 16:57:26 +00:00
import os
import re
from bs4 import BeautifulSoup
from funcs import read_from_json, save_to_file_by_address
base_address = os.getcwd()
html_address = base_address + "/main_qa_data/data/sections_set_02.json"
data = read_from_json(html_address)
html = ''
start_part = "<html><body style='direction: rtl;'>"
end_part = "</body></html>"
for i, line in enumerate(data):
id = line["id"]
content = line["content"]
result = line["result"]
sentences = result.split("*")
#start_part = "<html><body style='direction: rtl;'>"
#end_part = "</body></html>"
html_id = "<h4>" + id + "</h4>"
html_content = "<p class='content'>" + content + "</p>"
html_sentences = ''
for item in sentences:
if not item: continue
html_sentences += "<p class='sentence'>" + item + "</p>"
html += html_id + html_content + html_sentences + "<hr>"
style = """<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 100%;
left: 50%;
margin-left: -60px;
/* Fade in tooltip - takes 1 second to go from 0% to 100% opac: */
opacity: 0;
transition: opacity 1s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
.content {
font-size: 22px;
background-color: LightGray;
}
.sentence {
font-size: 18px;
}
</style>"""
html_file = start_part + style + html + end_part
result_address = base_address + "/main_qa_data/data/simple_sentences_02.html"
save_to_file_by_address(result_address, html_file)