замени перенос строки на тег
import os
Function to get the number of lines in a file
def get_line_count(file_path):
with open(file_path, "r", encoding="utf-8") as file:
lines = file.readlines()
return len(lines)
Generate the HTML table
def generate_html_table():
folder_path = "full_list"
file_links = []
file_counts = []
# Get the list of files in the folder
files = os.listdir(folder_path)
for file_name in files:
# Get the file path
file_path = os.path.join(folder_path, file_name)
# Get the file link
file_link = "ftp://" + file_name
file_links.append(file_link)
# Get the line count
line_count = get_line_count(file_path)
file_counts.append(line_count)
# Generate the HTML table
table_html = "<table>"
table_html += "<tr><th>File Name</th><th>Line Count</th></tr>"
for i in range(len(files)):
# Get the file name without extension
file_name = os.path.splitext(files[i])[0]
# Add the link to the file name
file_name_link = '<a href="' + file_links[i] + '">' + file_name + '</a>'
# Add the line count
line_count = file_counts[i]
# Generate the table row
table_html += "<tr>"
table_html += "<td>{}</td>".format(file_name_link)
table_html += "<td class='line-count' data-file='{}'>{}</td>".format(file_path, line_count)
table_html += "</tr>"
table_html += "</table>"
return table_html
Generate the HTML file
def generate_html_file():
# Generate the table HTML
table_html = generate_html_table()
# Prepare the HTML file content
html_content = """
<html>
<head>
<style>
.line-list {
display: none;
}
</style>
<script>
window.onload = function() {
// Show line list on click
var lineCells = document.getElementsByClassName('line-count');
for (var i=0; i<lineCells.length; i++) {
lineCells[i].addEventListener('click', function() {
var file = this.getAttribute('data-file');
var lineList = document.getElementById(file);
lineList.style.display = (lineList.style.display == 'none' ? 'block' : 'none');
});
}
// Filter lines on input
var filterInput = document.getElementById('filter-input');
filterInput.addEventListener('input', function() {
var filterValue = this.value.toLowerCase();
var lines = document.getElementsByClassName('line');
for (var i=0; i<lines.length; i++) {
var lineText = lines[i].textContent.toLowerCase();
lines[i].style.display = (lineText.includes(filterValue) ? 'block' : 'none');
}
});
}
</script>
</head>
<body>{}
<input type="text" id="filter-input" placeholder="Search">
</body>
</html>
""".format(table_html)
# Write the HTML file
with open("output.html", "w", encoding="utf-8") as file:
file.write(html_content)
Run the script
generate_html_file()