# -*- coding: utf-8 -*-
r"""B104: dọn thư mục tạm — giữ 1 bản chính (_zalo_tri_1310_today) + 3 ảnh chèn trong QC\images.
Xoá: _zalo_tri_1310 (15 ảnh hôm nay bản nhỏ), _zalo_tri_1310_full + _agy_tri_1310 (toàn ảnh NGÀY 12/10 bị lẫn)."""
import glob, os, shutil

QC = r'C:\Claw 2\QC'
GIU = os.path.join(QC, 'images', '_zalo_tri_1310_today')
print('  KIỂM trước khi xoá:')
print('   bản chính : %d ảnh gốc hôm nay' % len(glob.glob(os.path.join(GIU, 'today_*.jpg'))))
print('   ảnh đã chèn trong báo cáo: %d' % len(glob.glob(os.path.join(QC, 'images', 'tri_aq455_hoinai1_*.jpg'))))
assert len(glob.glob(os.path.join(GIU, 'today_*.jpg'))) == 15, 'THIẾU ẢNH — DỪNG'
assert len(glob.glob(os.path.join(QC, 'images', 'tri_aq455_hoinai1_*.jpg'))) == 3, 'THIẾU ẢNH CHÈN — DỪNG'

for ten in ('_zalo_tri_1310', '_zalo_tri_1310_full', '_agy_tri_1310'):
    d = os.path.join(QC, 'images', ten)
    if os.path.isdir(d):
        n = len(glob.glob(os.path.join(d, '*')))
        shutil.rmtree(d)
        print('   đã xoá %-24s (%d tệp)' % (ten, n))
    else:
        print('   (không có %s)' % ten)
print('  còn lại trong images/:')
for d in sorted(os.listdir(os.path.join(QC, 'images'))):
    p = os.path.join(QC, 'images', d)
    if os.path.isdir(p):
        print('   %-28s %d tệp' % (d, len(glob.glob(os.path.join(p, '*')))))
