# -*- coding: utf-8 -*-
r"""B108: verify zip bộ app — có đủ file từng app, KHÔNG có file mật khẩu, DB đủ, đọc README."""
import hashlib, os, zipfile

ZIP = r'C:\Claw 2\_BO_APP_MAU_QUYTRINH_20261014\BO_APP_MAU_VA_QUY_TRINH_20261014.zip'
z = zipfile.ZipFile(ZIP)
ds = z.infolist()
print('  tổng %d tệp | %d B | sha256 %s' % (len(ds), os.path.getsize(ZIP),
      hashlib.sha256(open(ZIP, 'rb').read()).hexdigest()[:24]))
print()
print('  --- theo thư mục:')
theo = {}
for i in ds:
    p = i.filename.split('/')
    k = '/'.join(p[:2]) if len(p) > 2 else i.filename
    theo[k] = theo.get(k, 0) + 1
for k in sorted(theo):
    print('   %-34s %2d tệp' % (k, theo[k]))
print()
print('  --- kiểm an toàn:')
xau = [i.filename for i in ds if any(x in i.filename.lower() for x in ('mat_khau', 'pass_', 'bi_mat', 'password', '__pycache__', '/viec/', '_backup'))]
print('   file mật khẩu/rác còn sót:', len(xau), xau[:5])
print('  --- DB + file chính:')
for i in ds:
    if i.filename.endswith('.db') or i.filename.endswith('.bat') or i.filename.endswith('.md'):
        print('   %-52s %8d B' % (i.filename, i.file_size))
print()
print('  --- README (300 ký tự đầu):')
print(z.read('BO_APP_MAU_VA_QUY_TRINH/README_BO_APP.md').decode('utf-8')[:300])
