import re
import sys

final_html_path = r'd:\DN\final_page_project\final-page.html'
shared_html_path = r'd:\DN\final_page_project\shared-hosting.html'

with open(final_html_path, 'r', encoding='utf-8') as f:
    final_html = f.read()

# Extract FAQ from final-page
faq_match = re.search(r'(<section class="faq-page\s*">.*?</section>)', final_html, re.DOTALL)
if not faq_match:
    print("FAQ not found in final-page.html")
    sys.exit(1)
faq_html = faq_match.group(1)

with open(shared_html_path, 'r', encoding='utf-8') as f:
    shared_html = f.read()

pricing_match = re.search(r'(<section id="pricing".*?</section>)', shared_html, re.DOTALL)
if not pricing_match:
    print("Pricing not found in shared-hosting.html")
    sys.exit(1)
pricing_end = pricing_match.end()

footer_match = re.search(r'(<footer class="theme-footer".*?</footer>)', shared_html, re.DOTALL)
if not footer_match:
    # try searching just for <footer
    footer_match = re.search(r'(<footer.*?</footer>)', shared_html, re.DOTALL)
    if not footer_match:
        print("Footer not found in shared-hosting.html")
        sys.exit(1)
footer_start = footer_match.start()

# Keep everything before pricing end
before_pricing = shared_html[:pricing_end]

# Keep everything from footer start to the end
after_footer = shared_html[footer_start:]

# Inject FAQ
new_shared = before_pricing + "\n\n" + faq_html + "\n\n" + after_footer

with open(shared_html_path, 'w', encoding='utf-8') as f:
    f.write(new_shared)

print("Successfully updated shared-hosting.html with final-page.html's FAQ section.")
