# -*- coding: utf-8 -*-
r"""B185: xem cau truc portal de chuan bi chen 5 khoi moi + 5 panel."""
import io, re

P = r'C:\Claw 2\Bao cao - Hanh chinh\BAOCAOTONGHOP\HTML\KPH_TongHop_0508\index.html'
h = io.open(P, encoding='utf-8').read()
print('  file: %d byte | LF=%d CRLF=%d' % (len(h.encode()), h.count('\n'), h.count('\r\n')))

# 1) cấu trúc cuối file + vị trí </section>
i = h.rfind('</section>')
print('\n  === cuoi file (tu vi tri %d):' % i)
print(re.sub(r'\n{2,}', '\n', h[i - 700:])[:1500])

# 2) một khối đã có PANEL làm mẫu
for slug in ('thanhthang-thth91', 'tv'):
    j = h.find('id="%s"' % slug)
    if j < 0:
        print('\n  === %s KHONG THAY' % slug); continue
    k = h.find('<!-- ============', j + 10)
    seg = h[j:k if k > 0 else j + 14000]
    print('\n  === khoi %s (%d ky tu) — 1200 ky tu CUOI:' % (slug, len(seg)))
    print(seg[-1200:])
