import os
from bs4 import BeautifulSoup

def add_buttons_to_plans():
    file_path = r'd:\DN\NIKITA_RAjput\ssl.html'
    
    with open(file_path, 'r', encoding='utf-8') as f:
        html_content = f.read()
        
    soup = BeautifulSoup(html_content, 'html.parser')
    
    # Find all plan bodies
    plans = soup.find_all('div', class_='plan')
    count = 0
    
    for plan in plans:
        plan_body = plan.find('div', class_='plan-body')
        if plan_body:
            # Check if button already exists
            existing_action = plan_body.find('div', class_='actions')
            if not existing_action:
                actions = soup.new_tag('div', attrs={'class': 'actions', 'style': 'margin-top: 20px;'})
                btn = soup.new_tag('a', attrs={'href': '#', 'class': 'btn btn-fill-primary shadow-off w-100'})
                btn.string = "Choose Plan"
                actions.append(btn)
                plan_body.append(actions)
                count += 1

    if count > 0:
        with open(file_path, 'w', encoding='utf-8') as f:
            f.write(str(soup))
        print(f"Added buttons to {count} plans successfully.")
    else:
        print("No buttons needed adding.")

if __name__ == "__main__":
    add_buttons_to_plans()
