84 lines
3.6 KiB
Python
84 lines
3.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
simple_combine.py - Simple script to insert content from two HTML files into the main HTML file
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
|
|
|
|
def simple_combine():
|
|
# Define file paths
|
|
main_file_path = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/scheduler_bots/Thesis materials/Thesis_ Intelligent School Schedule Management System.html"
|
|
file1_path = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/scheduler_bots/Thesis materials/deepseek_html_20260128_0dc71d.html"
|
|
file2_path = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/scheduler_bots/Thesis materials/deepseek_html_20260128_15ee7a.html"
|
|
|
|
# Read the main file content
|
|
with open(main_file_path, 'r', encoding='utf-8') as f:
|
|
main_content = f.read()
|
|
|
|
# Read the content from the first file
|
|
with open(file1_path, 'r', encoding='utf-8') as f:
|
|
file1_content = f.read()
|
|
|
|
# Read the content from the second file
|
|
with open(file2_path, 'r', encoding='utf-8') as f:
|
|
file2_content = f.read()
|
|
|
|
# Remove HTML structure from the additional files (doctype, html, head, body tags)
|
|
def clean_html_content(content):
|
|
# Remove doctype
|
|
content = re.sub(r'<!DOCTYPE[^>]*>', '', content, flags=re.IGNORECASE)
|
|
# Remove html tags
|
|
content = re.sub(r'<html[^>]*>|</html>', '', content, flags=re.IGNORECASE)
|
|
# Remove head section
|
|
content = re.sub(r'<head[^>]*>.*?</head>', '', content, flags=re.DOTALL | re.IGNORECASE)
|
|
# Remove body tags
|
|
content = re.sub(r'<body[^>]*>|</body>', '', content, flags=re.IGNORECASE)
|
|
return content.strip()
|
|
|
|
# Clean the content from both files
|
|
clean_file1_content = clean_html_content(file1_content)
|
|
clean_file2_content = clean_html_content(file2_content)
|
|
|
|
# Find the closing body tag to insert additional content
|
|
body_close_pos = main_content.rfind('</body>')
|
|
if body_close_pos == -1:
|
|
# If no closing body tag, find the closing html tag
|
|
html_close_pos = main_content.rfind('</html>')
|
|
if html_close_pos != -1:
|
|
insert_pos = html_close_pos
|
|
else:
|
|
# If no closing html tag, append at the end
|
|
insert_pos = len(main_content)
|
|
else:
|
|
insert_pos = body_close_pos
|
|
|
|
# Prepare the additional content to insert
|
|
additional_content = f'''
|
|
<!-- Additional Content from deepseek_html_20260128_0dc71d.html -->
|
|
<section class="additional-content" style="margin: 40px 0; padding: 20px; border: 1px solid #ccc; border-radius: 8px;">
|
|
<h2 style="color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;">Additional Content Section 1</h2>
|
|
{clean_file1_content}
|
|
</section>
|
|
|
|
<!-- Additional Content from deepseek_html_20260128_15ee7a.html -->
|
|
<section class="additional-content" style="margin: 40px 0; padding: 20px; border: 1px solid #ccc; border-radius: 8px;">
|
|
<h2 style="color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;">Additional Content Section 2</h2>
|
|
{clean_file2_content}
|
|
</section>
|
|
'''
|
|
|
|
# Insert the additional content into the main file
|
|
combined_content = main_content[:insert_pos] + additional_content + main_content[insert_pos:]
|
|
|
|
# Write the combined content back to the main file
|
|
with open(main_file_path, 'w', encoding='utf-8') as f:
|
|
f.write(combined_content)
|
|
|
|
print("Content from both files has been successfully inserted into the main HTML file.")
|
|
print(f"Updated file: {main_file_path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
simple_combine() |