Skip to content

Commit

Permalink
feat: add CSS to HTML template (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazzabeee authored May 1, 2024
1 parent 9c8312f commit 16f8f52
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ __pycache__/

.idea/

src/slate3k/

# Distribution / packaging
.Python
build/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $ pip install pytest
$ pytest tests/

# Run package locally
$ python -m scripts.main.py [-s] [-o] [-h] input_directory
$ python -m scripts.main [-s] [-o] [-h] input_directory
```

**Recommandations**
Expand Down
Empty file removed pyproject.toml
Empty file.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e git+https://github.com/Wazzabeee/slate3k#egg=slate3k
beautifulsoup4==4.10.0
nltk==3.6.6
odfpy==1.4.1
pdfplumber==0.5.28
slate3k==0.5.3
tabulate==0.8.9
6 changes: 3 additions & 3 deletions scripts/html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def writing_results(dir_name: str) -> str:
def get_color_from_similarity(similarity_score: float) -> str:
"""Return css style according to similarity score"""

if float(similarity_score) > 15:
if similarity_score > 15:
return "#990033; font-weight: bold"
if float(similarity_score) > 10:
if similarity_score > 10:
return "#ff6600"
if float(similarity_score) > 5:
if similarity_score > 5:
return "#ffcc00"

return "green"
14 changes: 8 additions & 6 deletions scripts/html_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from os import fsync, rename, path
from os import fsync, path
from random import randint
from shutil import copy
from typing import Any, List
Expand Down Expand Up @@ -43,7 +43,7 @@ def add_links_to_html_table(html_path: str) -> None:
"a",
href="file:///" + html_path.replace("_results", str(file_ind)),
target="_blank",
style="color:" + get_color_from_similarity(td_tag.text),
style="color:" + get_color_from_similarity(float(td_tag.text)),
)

td_tag.string.wrap(tmp) # We wrap the td string between the hyperlink
Expand Down Expand Up @@ -114,15 +114,16 @@ def get_span_blocks(bs_obj: Bs, text1: list, text2: list, block_size: int) -> li

def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenames: tuple, block_size: int) -> None:
"""Write to HTML file texts that have been compared with highlighted similar blocks"""

copy(path.join("templates", "template.html"), save_dir) # Copy comparison template to curr dir
template_path = path.join("templates", "template.html")
comp_path = path.join(save_dir, str(ind) + ".html")
rename(path.join(save_dir, "template.html"), comp_path)

# Copy the template to the save directory under a new name
copy(template_path, comp_path)

with open(comp_path, encoding="utf-8") as html:
soup = Bs(html, "html.parser")
res = get_span_blocks(soup, text1, text2, block_size)
blocks = soup.findAll(attrs={"class": "block"})
blocks = [soup.find(id="leftContent"), soup.find(id="rightContent")]

# Append filename tags and span tags to html
for i, filename in enumerate(filenames):
Expand All @@ -132,6 +133,7 @@ def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenam
for tag in res[i]:
blocks[i].append(tag)

# Write the modified content back to the file
with open(comp_path, "wb") as f_output:
f_output.write(soup.prettify("utf-8"))

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ disable=C0103,C0114,R0913,R0914,C0200,C0301
[pep8]
max-line-length=120
ignore=E121,E123,E126,E226,E24,E704,E203,W503
exclude=venv,test_env,test_venv
exclude=venv,test_env,test_venv,slate3k

[flake8]
max-line-length=120
ignore=E121,E123,E126,E226,E24,E704,E203,W503
exclude=venv,test_env,test_venv
exclude=venv,test_env,test_venv,slate3k
67 changes: 53 additions & 14 deletions templates/template.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
<html>
<head>
<title>
</title>
</head>
<body>
<div style="width: 100%; overflow: hidden;">

<div style="width: 46%; float: left;" class="block"> </div>

<div style="margin-left: 50%;" class="block"> </div>

</div>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plagiarism Detection Results</title>
<style>
body, html {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}

.container {
display: flex;
justify-content: space-between;
padding: 20px;
}

.content {
width: 48%;
border: 1px solid #ddd;
padding: 10px;
overflow: auto;
height: 90vh;
}

h3 {
color: #333;
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
}

span {
display: block;
}

a {
color: #06c;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<div class="content" id="leftContent"></div>
<div class="content" id="rightContent"></div>
</div>
</body>
</html>

0 comments on commit 16f8f52

Please sign in to comment.