From 4b79ae5561bb9877f17c3a6c08f14b8f7958d54c Mon Sep 17 00:00:00 2001 From: mayank puvvala Date: Sun, 14 Apr 2024 23:51:56 +0530 Subject: [PATCH] Add files via upload --- Merging.ipynb | 361 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 Merging.ipynb diff --git a/Merging.ipynb b/Merging.ipynb new file mode 100644 index 0000000..60b5af3 --- /dev/null +++ b/Merging.ipynb @@ -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('\\n\\n\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('\\n\\n')\n", + " \n", + " # Write the button to show/hide the TOC\n", + " merged_file.write('
Toggle TOC
\\n')\n", + " \n", + " # Write the table of contents\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\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('

') + len('

')\n", + " title_end_index = html_content.find('

')\n", + " title = html_content[title_index:title_end_index]\n", + " \n", + " # Find the index of the Overview section\n", + " overview_index = html_content.find('

Overview

')\n", + " \n", + " # Write the section before the Overview\n", + " merged_file.write(f'
\\n')\n", + " merged_file.write(f'
{title}
\\n')\n", + " merged_file.write(html_content[:overview_index])\n", + " merged_file.write('
\\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('\\n')\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('\\n\\n\\n\\n\\n')\n", + " \n", + " # Write the table of contents\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\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'
\\n')\n", + " merged_file.write(f'

{file_name}

\\n')\n", + " merged_file.write(html_content)\n", + " merged_file.write('
\\n')\n", + " \n", + " # Write the closing HTML tags\n", + " merged_file.write('\\n')\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('\\n\\n\\n\\n\\n')\n", + " \n", + " # Write the TOC button\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\n')\n", + " \n", + " # Write the table of contents\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\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'
\\n')\n", + " merged_file.write(f'

{file_name}

\\n')\n", + " merged_file.write(html_content)\n", + " merged_file.write('
\\n')\n", + " \n", + " # Write the JavaScript function for toggling TOC visibility\n", + " merged_file.write('\\n')\n", + " \n", + " # Write the closing HTML tags\n", + " merged_file.write('\\n')\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('\\n\\n\\n\\n\\n')\n", + " \n", + " # Write the table of contents button\n", + " merged_file.write('\\n')\n", + " \n", + " # Write the table of contents\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\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'
\\n')\n", + " merged_file.write(f'

{title}

\\n')\n", + " merged_file.write(html_content)\n", + " merged_file.write('
\\n')\n", + " \n", + " # Write the closing HTML tags\n", + " merged_file.write('\\n')\n", + " merged_file.write('\\n')\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('\\n\\n\\n\\n\\n')\n", + " \n", + " # Write the table of contents button\n", + " merged_file.write('\\n')\n", + " \n", + " # Write the table of contents\n", + " merged_file.write('
\\n')\n", + " merged_file.write('\\n')\n", + " merged_file.write('
\\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'
\\n')\n", + " merged_file.write(f'

{title}

\\n')\n", + " merged_file.write(minified_html)\n", + " merged_file.write('
\\n')\n", + " \n", + " # Write the closing HTML tags\n", + " merged_file.write('\\n')\n", + " merged_file.write('\\n')\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 +}