# -*- coding: utf-8 -*-
r"""B63: kiểm file báo cáo làm mẫu đã về chưa (cache documents + thư mục chuẩn) + xác định tuần ISO."""
import datetime, glob, os, re, time

print('  Hôm nay: %s | Tuần ISO: %s | Thứ: %s' % (
    datetime.date.today().strftime('%d/%m/%Y'), datetime.date.today().isocalendar()[1],
    ['Thứ 2', 'Thứ 3', 'Thứ 4', 'Thứ 5', 'Thứ 6', 'Thứ 7', 'CN'][datetime.date.today().weekday()]))
print()
print('  === cache documents (file chủ nhân gửi qua Telegram) ===')
DOC = os.path.join(os.environ['LOCALAPPDATA'], 'hermes', 'cache', 'documents')
ds = sorted(glob.glob(os.path.join(DOC, '*')), key=os.path.getmtime, reverse=True)[:12]
for p in ds:
    t = datetime.datetime.fromtimestamp(os.path.getmtime(p))
    print('   %s  %10d B  %s' % (t.strftime('%d/%m %H:%M'), os.path.getsize(p), os.path.basename(p)[:80]))
print()
print('  === thư mục chuẩn "Bao cao lam mau" ===')
D = r'C:\Claw 2\Bao cao - Hanh chinh\Bao cao lam mau'
if os.path.isdir(D):
    for f in sorted(os.listdir(D), key=lambda x: os.path.getmtime(os.path.join(D, x)), reverse=True)[:14]:
        p = os.path.join(D, f)
        t = datetime.datetime.fromtimestamp(os.path.getmtime(p))
        print('   %s  %s  %s' % (t.strftime('%d/%m %H:%M'), ('%10d B' % os.path.getsize(p)) if os.path.isfile(p) else '[thư mục]', f[:70]))
    if os.path.isdir(os.path.join(D, 'da lam sach')):
        print('   --- da lam sach:')
        for f in sorted(os.listdir(os.path.join(D, 'da lam sach')), key=lambda x: os.path.getmtime(os.path.join(D, 'da lam sach', x)), reverse=True)[:10]:
            p = os.path.join(D, 'da lam sach', f)
            t = datetime.datetime.fromtimestamp(os.path.getmtime(p))
            print('      %s  %s  %s' % (t.strftime('%d/%m %H:%M'), ('%10d B' % os.path.getsize(p)) if os.path.isfile(p) else '[thư mục]', f[:66]))
else:
    print('   (không thấy thư mục)')
print()
print('  === file nào có tên chứa tuần 41/42 ===')
for pat in ('*41*', '*42*'):
    for p in glob.glob(os.path.join(D, pat)):
        print('   ', os.path.basename(p), os.path.getsize(p), 'B')
