# -*- coding: utf-8 -*-
"""Kiem DOCX tien do 37-40 + copy 2 file gui sang thu muc khong dau cach."""
import os, shutil
from docx import Document

LAM = r'C:\Claw 2\Bao cao - Hanh chinh\Bao cao lam mau'
DOM = r'C:\Users\admin\AppData\Local\hermes\cache\gui_t40'
os.makedirs(DOM, exist_ok=True)

p = os.path.join(LAM, 'Bao cao', 'Bao_cao_tien_do_lam_mau_tuan_37_40.docx')
d = Document(p)
txt = '\n'.join(x.text for x in d.paragraphs)
cell = '\n'.join(cc.text for t in d.tables for r in t.rows for cc in r.cells)
print('DOCX:', os.path.basename(p), os.path.getsize(p), 'byte | doan:', len(d.paragraphs), '| bang:', len(d.tables))
print('  kich thuoc bang:', [(len(t.rows), len(t.columns)) for t in d.tables])
print('  tieu de:', repr(d.paragraphs[0].text[:120]))
for k in ['37', '38', '39', '40']:
    print('  co %s:' % k, (k in txt) or (k in cell))
print('  so lan xuat hien "Tuần 40":', (txt + cell).count('Tuần 40'), '| "40" tong:', (txt + cell).count('40'))

for src in [r'C:\Claw 2\Bao cao - Hanh chinh\BAOCAOTONGHOP\HTML\Tuan 40\Bao_cao_LamMau_Tuan40_Portal.html', p]:
    dst = os.path.join(DOM, os.path.basename(src))
    shutil.copy2(src, dst)
    print('copy ->', dst, os.path.getsize(dst), 'byte')
print('thu muc gui:', os.listdir(DOM))
