import re import os import shutil src_file = '/workspace/personal/dashboards/marketing/index.html' bak_file = '/workspace/personal/dashboards/marketing/index.html.bak' if not os.path.exists(bak_file): shutil.copyfile(src_file, bak_file) print("Backup created at", bak_file) with open(src_file, 'r', encoding='utf-8') as f: html = f.read() # 1. Update navbar-nav-list nav_item_html = ''' ''' if 'id="navItemMarketingOps"' not in html: # replace navItemChannels active state html = html.replace('