Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankpuvvala authored Apr 14, 2024
1 parent ad8d367 commit 4b79ae5
Showing 1 changed file with 361 additions and 0 deletions.
361 changes: 361 additions & 0 deletions Merging.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,361 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "5aa4e6d6-6d73-4364-b052-2d70ec3ab029",
"metadata": {},
"outputs": [],
"source": [
"# List of HTML files to merge\n",
"html_files = ['Accused_Details.html', 'AccFir.html', 'Accident_Reports.html', 'Accident_Complainant.html']\n",
"\n",
"# Open the merged HTML file\n",
"with open('Main3.html', 'w', encoding='utf-8') as merged_file:\n",
" # Write the opening HTML tags\n",
" merged_file.write('<html>\\n<head>\\n<style>\\n')\n",
" \n",
" # Add CSS for styling\n",
" merged_file.write('body { font-family: Arial, sans-serif; }\\n')\n",
" merged_file.write('.section { margin-bottom: 20px; }\\n')\n",
" merged_file.write('.section-heading { margin-left: 20px; border-left: 2px solid #ccc; padding-left: 10px; }\\n')\n",
" merged_file.write('.toc { position: fixed; top: 50px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; display: none; }\\n')\n",
" merged_file.write('.toc ul { list-style-type: none; padding-left: 0; }\\n')\n",
" merged_file.write('.toc li { margin-bottom: 5px; }\\n')\n",
" merged_file.write('.show-toc { position: fixed; top: 10px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 5px; cursor: pointer; }\\n')\n",
" merged_file.write('</style>\\n')\n",
" merged_file.write('<script>\\n')\n",
" merged_file.write('function toggleTOC() {\\n')\n",
" merged_file.write('var toc = document.querySelector(\".toc\");\\n')\n",
" merged_file.write('if (toc.style.display === \"none\") {\\n')\n",
" merged_file.write('toc.style.display = \"block\";\\n')\n",
" merged_file.write('} else {\\n')\n",
" merged_file.write('toc.style.display = \"none\";\\n')\n",
" merged_file.write('}\\n')\n",
" merged_file.write('}\\n')\n",
" merged_file.write('</script>\\n')\n",
" merged_file.write('</head>\\n<body>\\n')\n",
" \n",
" # Write the button to show/hide the TOC\n",
" merged_file.write('<div class=\"show-toc\" onclick=\"toggleTOC()\">Toggle TOC</div>\\n')\n",
" \n",
" # Write the table of contents\n",
" merged_file.write('<div class=\"toc\">\\n')\n",
" merged_file.write('<ul>\\n')\n",
" for html_file in html_files:\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" # Get the title of the HTML file (assuming it's the first h1 tag)\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" html_content = current_file.read()\n",
" title_index = html_content.find('<h1>') + len('<h1>')\n",
" title_end_index = html_content.find('</h1>')\n",
" title = html_content[title_index:title_end_index]\n",
" merged_file.write(f'<li><a href=\"#{file_name}\">{title}</a></li>\\n')\n",
" merged_file.write('</ul>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Loop through each HTML file\n",
" for html_file in html_files:\n",
" # Open the current HTML file\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" # Read all lines of the HTML file\n",
" html_content = current_file.read()\n",
" \n",
" # Write the section with file title as the ID\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" # Get the title of the HTML file (assuming it's the first h1 tag)\n",
" title_index = html_content.find('<h1>') + len('<h1>')\n",
" title_end_index = html_content.find('</h1>')\n",
" title = html_content[title_index:title_end_index]\n",
" \n",
" # Find the index of the Overview section\n",
" overview_index = html_content.find('<h2>Overview</h2>')\n",
" \n",
" # Write the section before the Overview\n",
" merged_file.write(f'<div id=\"{file_name}\" class=\"section\">\\n')\n",
" merged_file.write(f'<div class=\"section-heading\">{title}</div>\\n')\n",
" merged_file.write(html_content[:overview_index])\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the Overview section\n",
" merged_file.write(html_content[overview_index:])\n",
" \n",
" # Write the closing HTML tags\n",
" merged_file.write('</body>\\n</html>')\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cc23ee8d-996c-4ffa-90c3-e30219e85655",
"metadata": {},
"outputs": [],
"source": [
"# List of HTML files to merge\n",
"html_files = ['Accused_Details.html', 'AccFir.html', 'Accident_Reports.html', 'Accident_Complainant.html', 'Accident_Victim.html']\n",
"\n",
"# Open the merged HTML file\n",
"with open('Main4.html', 'w', encoding='utf-8') as merged_file:\n",
" # Write the opening HTML tags\n",
" merged_file.write('<html>\\n<head>\\n<style>\\n')\n",
" \n",
" # Add CSS for styling\n",
" merged_file.write('body { font-family: Arial, sans-serif; }\\n')\n",
" merged_file.write('.section { margin-bottom: 20px; }\\n')\n",
" merged_file.write('.toc { position: fixed; top: 50px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; }\\n')\n",
" merged_file.write('.toc ul { list-style-type: none; padding-left: 0; }\\n')\n",
" merged_file.write('.toc li { margin-bottom: 5px; }\\n')\n",
" merged_file.write('</style>\\n</head>\\n<body>\\n')\n",
" \n",
" # Write the table of contents\n",
" merged_file.write('<div class=\"toc\">\\n')\n",
" merged_file.write('<ul>\\n')\n",
" for html_file in html_files:\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<li><a href=\"#{file_name}\">{file_name}</a></li>\\n')\n",
" merged_file.write('</ul>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Loop through each HTML file\n",
" for html_file in html_files:\n",
" # Open the current HTML file\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" # Read all lines of the HTML file\n",
" html_content = current_file.read()\n",
" \n",
" # Write the section with file title as the ID\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<div id=\"{file_name}\" class=\"section\">\\n')\n",
" merged_file.write(f'<h2>{file_name}</h2>\\n')\n",
" merged_file.write(html_content)\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the closing HTML tags\n",
" merged_file.write('</body>\\n</html>')\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "56d7a09b",
"metadata": {},
"outputs": [],
"source": [
"# List of HTML files to merge\n",
"html_files = ['Accused_Details.html', 'AccFir.html', 'Accident_Reports.html', 'Accident_Complainant.html', 'Accident_Victim.html']\n",
"\n",
"# Open the merged HTML file\n",
"with open('Main5.html', 'w', encoding='utf-8') as merged_file:\n",
" # Write the opening HTML tags\n",
" merged_file.write('<html>\\n<head>\\n<style>\\n')\n",
" \n",
" # Add CSS for styling\n",
" merged_file.write('body { font-family: Arial, sans-serif; }\\n')\n",
" merged_file.write('.section { margin-bottom: 20px; text-align: center; padding: 10px; }\\n')\n",
" merged_file.write('.toc { position: fixed; top: 50px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; }\\n')\n",
" merged_file.write('.toc ul { list-style-type: none; padding-left: 0; }\\n')\n",
" merged_file.write('.toc li { margin-bottom: 5px; }\\n')\n",
" merged_file.write('.toc-button { position: fixed; top: 10px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 5px; }\\n')\n",
" merged_file.write('</style>\\n</head>\\n<body>\\n')\n",
" \n",
" # Write the TOC button\n",
" merged_file.write('<div class=\"toc-button\">\\n')\n",
" merged_file.write('<button onclick=\"toggleTOC()\">Table of Contents</button>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the table of contents\n",
" merged_file.write('<div class=\"toc\" id=\"toc\">\\n')\n",
" merged_file.write('<ul>\\n')\n",
" for html_file in html_files:\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<li><a href=\"#{file_name}\">{file_name}</a></li>\\n')\n",
" merged_file.write('</ul>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Loop through each HTML file\n",
" for html_file in html_files:\n",
" # Open the current HTML file\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" # Read all lines of the HTML file\n",
" html_content = current_file.read()\n",
" \n",
" # Write the section with file title as the ID\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<div id=\"{file_name}\" class=\"section\">\\n')\n",
" merged_file.write(f'<h2 style=\"padding: 10px;\">{file_name}</h2>\\n')\n",
" merged_file.write(html_content)\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the JavaScript function for toggling TOC visibility\n",
" merged_file.write('<script>\\n')\n",
" merged_file.write('function toggleTOC() {\\n')\n",
" merged_file.write('var toc = document.getElementById(\"toc\");\\n')\n",
" merged_file.write('if (toc.style.display === \"none\") {\\n')\n",
" merged_file.write('toc.style.display = \"block\";\\n')\n",
" merged_file.write('} else {\\n')\n",
" merged_file.write('toc.style.display = \"none\";\\n')\n",
" merged_file.write('}\\n')\n",
" merged_file.write('}\\n')\n",
" merged_file.write('</script>\\n')\n",
" \n",
" # Write the closing HTML tags\n",
" merged_file.write('</body>\\n</html>')\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3adfe67e",
"metadata": {},
"outputs": [],
"source": [
"# List of HTML files to merge\n",
"html_files = ['Accused_Details.html', 'AccFir.html', 'Accident_Reports.html', 'Accident_Complainant.html', 'Accident_Victim.html']\n",
"\n",
"# Titles corresponding to the HTML files\n",
"titles = ['Accused Insights', 'FIR Insights', 'Accident Reports Insights', 'Accident Complainant Insights', 'Accident Victim Insights']\n",
"\n",
"# Open the merged HTML file\n",
"with open('Main5.html', 'w', encoding='utf-8') as merged_file:\n",
" # Write the opening HTML tags\n",
" merged_file.write('<html>\\n<head>\\n<style>\\n')\n",
" \n",
" # Add CSS for styling\n",
" merged_file.write('body { font-family: Arial, sans-serif; }\\n')\n",
" merged_file.write('.section { margin-bottom: 20px; text-align: center; padding: 10px; }\\n')\n",
" merged_file.write('.toc { position: fixed; top: 50px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; }\\n')\n",
" merged_file.write('.toc ul { list-style-type: none; padding-left: 0; }\\n')\n",
" merged_file.write('.toc li { margin-bottom: 5px; }\\n')\n",
" merged_file.write('.toc-button { position: fixed; top: 10px; right: 10px; padding: 5px 10px; background-color: #f0f0f0; border: 1px solid #ccc; }\\n')\n",
" merged_file.write('</style>\\n</head>\\n<body>\\n')\n",
" \n",
" # Write the table of contents button\n",
" merged_file.write('<button class=\"toc-button\" onclick=\"toggleTOC()\">Table of Contents</button>\\n')\n",
" \n",
" # Write the table of contents\n",
" merged_file.write('<div class=\"toc\" id=\"toc\">\\n')\n",
" merged_file.write('<ul>\\n')\n",
" for title, html_file in zip(titles, html_files):\n",
" merged_file.write(f'<li><a href=\"#{html_file.split(\".\")[0]}\">{title}</a></li>\\n')\n",
" merged_file.write('</ul>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Loop through each HTML file\n",
" for title, html_file in zip(titles, html_files):\n",
" # Open the current HTML file\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" # Read all lines of the HTML file\n",
" html_content = current_file.read()\n",
" \n",
" # Write the section with file title as the ID\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<div id=\"{file_name}\" class=\"section\">\\n')\n",
" merged_file.write(f'<h2>{title}</h2>\\n')\n",
" merged_file.write(html_content)\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the closing HTML tags\n",
" merged_file.write('<script>\\nfunction toggleTOC() {\\nvar toc = document.getElementById(\"toc\");\\nif (toc.style.display === \"none\") {\\ntoc.style.display = \"block\";\\n} else {\\ntoc.style.display = \"none\";\\n}\\n}\\n</script>\\n')\n",
" merged_file.write('</body>\\n</html>')\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "851b8893",
"metadata": {},
"outputs": [],
"source": [
"import htmlmin\n",
"\n",
"# List of HTML files to merge\n",
"html_files = ['Accused_Details.html', 'AccFir.html', 'Accident_Reports.html', 'Accident_Complainant.html', 'Accident_Victim.html']\n",
"\n",
"# Titles corresponding to the HTML files\n",
"titles = ['Accused Insights', 'FIR Insights', 'Accident Reports Insights', 'Accident Complainant Insights', 'Accident Victim Insights']\n",
"\n",
"# Open the merged HTML file\n",
"with open('Main5_comp.html', 'w', encoding='utf-8') as merged_file:\n",
" # Write the opening HTML tags\n",
" merged_file.write('<html>\\n<head>\\n<style>\\n')\n",
" \n",
" # Add CSS for styling\n",
" merged_file.write('body { font-family: Arial, sans-serif; }\\n')\n",
" merged_file.write('.section { margin-bottom: 20px; text-align: center; padding: 10px; }\\n')\n",
" merged_file.write('.toc { position: fixed; top: 50px; right: 10px; background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; }\\n')\n",
" merged_file.write('.toc ul { list-style-type: none; padding-left: 0; }\\n')\n",
" merged_file.write('.toc li { margin-bottom: 5px; }\\n')\n",
" merged_file.write('.toc-button { position: fixed; top: 10px; right: 10px; padding: 5px 10px; background-color: #f0f0f0; border: 1px solid #ccc; }\\n')\n",
" merged_file.write('</style>\\n</head>\\n<body>\\n')\n",
" \n",
" # Write the table of contents button\n",
" merged_file.write('<button class=\"toc-button\" onclick=\"toggleTOC()\">Table of Contents</button>\\n')\n",
" \n",
" # Write the table of contents\n",
" merged_file.write('<div class=\"toc\" id=\"toc\">\\n')\n",
" merged_file.write('<ul>\\n')\n",
" for title, html_file in zip(titles, html_files):\n",
" merged_file.write(f'<li><a href=\"#{html_file.split(\".\")[0]}\">{title}</a></li>\\n')\n",
" merged_file.write('</ul>\\n')\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Loop through each HTML file\n",
" for title, html_file in zip(titles, html_files):\n",
" # Open the current HTML file\n",
" with open(html_file, 'r', encoding='utf-8') as current_file:\n",
" # Read all lines of the HTML file\n",
" html_content = current_file.read()\n",
" \n",
" # Minify HTML code\n",
" minified_html = htmlmin.minify(html_content)\n",
" \n",
" # Write the section with file title as the ID\n",
" file_name = html_file.split('.')[0] # Extract file name without extension\n",
" merged_file.write(f'<div id=\"{file_name}\" class=\"section\">\\n')\n",
" merged_file.write(f'<h2>{title}</h2>\\n')\n",
" merged_file.write(minified_html)\n",
" merged_file.write('</div>\\n')\n",
" \n",
" # Write the closing HTML tags\n",
" merged_file.write('<script>\\nfunction toggleTOC() {\\nvar toc = document.getElementById(\"toc\");\\nif (toc.style.display === \"none\") {\\ntoc.style.display = \"block\";\\n} else {\\ntoc.style.display = \"none\";\\n}\\n}\\n</script>\\n')\n",
" merged_file.write('</body>\\n</html>')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66dfe717",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 4b79ae5

Please sign in to comment.