ehsan-dashboards/dashboards/old_hermes/fix_b2b_dom_structure.py

37 lines
1.6 KiB
Python

import re
print("Fixing tabPaneGoogleAdsB2B DOM position outside of exportModal...")
with open('/workspace/live_marketing_index.html', 'r', encoding='utf-8') as f:
html = f.read()
# Fix exportModal closure
bad_block = """
<!-- TAB 4: GOOGLE ADS, B2B PACKAGES & VIP ROOM SALES -->
<div id="tabPaneGoogleAdsB2B" class="main-tab-pane" style="display: none; padding-bottom: 60px;">
<!-- Rendered by renderGoogleAdsB2BView() -->
</div>
</div>
</div>
</div>"""
good_block = """ </div>
</div>
</div>
<!-- TAB 4: GOOGLE ADS, B2B PACKAGES & VIP ROOM SALES -->
<div id="tabPaneGoogleAdsB2B" class="main-tab-pane" style="display: none; padding-bottom: 60px;">
<!-- Rendered by renderGoogleAdsB2BView() -->
</div>"""
if bad_block in html:
html = html.replace(bad_block, good_block)
print("Replaced bad block in live_marketing_index.html!")
else:
print("Searching for variations...")
html = re.sub(r'(\s*<button class="date-btn" style="padding: 10px; text-align: center;" onclick="downloadDataset\(\'csv\'\)">[\s\S]*?<\/button>)\s*<!-- TAB 4: GOOGLE ADS[\s\S]*?<\/div>\s*<\/div>\s*<\/div>\s*<\/div>', r'\1\n </div>\n </div>\n </div>\n\n <!-- TAB 4: GOOGLE ADS, B2B PACKAGES & VIP ROOM SALES -->\n <div id="tabPaneGoogleAdsB2B" class="main-tab-pane" style="display: none; padding-bottom: 60px;">\n <!-- Rendered by renderGoogleAdsB2BView() -->\n </div>', html)
with open('/workspace/live_marketing_index.html', 'w', encoding='utf-8') as f:
f.write(html)
print("Saved corrected live_marketing_index.html!")