import re

with open(r'D:\Evolução categorias\sistema_dfe.html', 'r', encoding='utf-8') as f:
    html = f.read()

# Find the page-dre section to understand current structure
m = re.search(r'(<div class="page" id="page-dre">)(.*?)(</div>\s*<!-- )', html, re.DOTALL)
if m:
    print("DRE section found, length:", len(m.group(2)))
    print(m.group(2)[:2000])
else:
    print("NOT FOUND")

# Check what monthly data keys exist
m2 = re.search(r'mensal_receita.*?(?=mensal_cmv)', html, re.DOTALL)
if m2:
    print("\nmensal_receita snippet:", m2.group()[:200])

# Check if buildDRE function exists and how it uses data
m3 = re.search(r'function buildDRE\(\).*?(?=\nfunction |\n  function )', html, re.DOTALL)
if m3:
    print("\nbuildDRE found, length:", len(m3.group()))
    print(m3.group()[:1000])
