#!/usr/bin/env python3
path = "/opt/1panel/apps/openresty/openresty/www/sites/nickys.cn/index/work/20260511/phone.html"
with open(path, "r", encoding="utf-8") as f:
    content = f.read()

# Find the exact position of topbar closing + cat-nav
# Pattern: </div></div><nav class="cat-nav"
old = '</div></div><nav class="cat-nav"'
hero_html = (
    '</div></div>\n'
    '<div class="hero-banner">\n'
    '  <div class="label">🔥 今日报价 · 2026年5月11日</div>\n'
    '  <h1>全系列手机报价<br><span>华为 · 苹果 · 荣耀 · 小米 · OPPO · vivo · IQOO</span></h1>\n'
    '  <p class="sub">批发价每日更新 · 量大价优 · 郑州科技市场实体店<br><em>📦 支持同城配送 · 全国发货</em></p>\n'
    '  <a href="tel:18637167337" class="phone">📞 18637167337</a>\n'
    '  <div class="date">郑州悦诚电子 · 2026年5月11日 星期一</div>\n'
    '</div>\n'
    '<nav class="cat-nav"'
)

if old in content:
    content = content.replace(old, hero_html, 1)
    print("hero html inserted successfully")
else:
    print("pattern not found, searching...")
    import re
    # Find the position
    m = re.search(r'</div></div><nav class="cat-nav"', content)
    if m:
        print(f"found at position {m.start()}")
        content = content[:m.start()] + '</div></div>\n' + hero_html.replace(old, '<nav class="cat-nav"') + content[m.end():]
        print("inserted via regex")
    else:
        print("not found at all")

with open(path, "w", encoding="utf-8") as f:
    f.write(content)
print("done")
