import re
h = open("/opt/coinglass-strategy/dashboard/factor_detail_charts.html").read()
m = re.search(r"<script>.*?</script>", h, re.DOTALL)
if m:
    js = m.group()
    o = js.count("{")
    c = js.count("}")
    po = js.count("(")
    pc = js.count(")")
    print(f"Braces: {o} open, {c} close, diff={o-c}")
    print(f"Parens: {po} open, {pc} close, diff={po-pc}")
    # Find volatility section
    idx = js.find("Volatility bars")
    if idx > 0:
        chunk = js[idx:idx+400]
        print(f"Volatility area:\n{chunk[:300]}")
    # Find the last 200 chars of JS
    print(f"\nJS ending:\n{js[-300:]}")
