naveed-stockmark's picture
Update utils.py
709cde5
raw
history blame contribute delete
No virus
1.15 kB
import json
def load_json(path):
"""load json object"""
with open(path, 'rb') as f:
data = json.load(f)
print("Loaded json from path: " + str(path))
return data
import difflib
def generate_diff_html(text_pairs, output_file=''):
diff_css = '''
<style>
ins {
color: white;
background-color: #d4fcbc;
text-decoration: none;
}
del {
background-color: #fbb6c2;
text-decoration: none;
}
</style>
'''
diff_html = '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="UTF-8">\n<title>Text Diff</title>\n'
diff_html += diff_css
diff_html += '\n</head>\n<body>\n'
for i, (text, text_processed) in enumerate(text_pairs, 1):
diff_html += f'<h3>Pair {i}</h3>\n'
d = difflib.HtmlDiff()
diff_table = d.make_table(text.splitlines(), text_processed.splitlines())
diff_html += diff_table
diff_html += '<br>\n'
diff_html += '</body>\n</html>'
if output_file != '':
with open(output_file, 'w') as f:
f.write(diff_html)
return diff_html