# -*- coding: utf-8 -*-
"""Copy lo anh 21:57 vao anh_vao\\ (khu trung md5), dat ten thu tu."""
import hashlib, os, shutil, time

CACHE = os.path.join(os.environ['LOCALAPPDATA'], 'hermes', 'cache', 'images')
D = r'C:\Claw 2\Nghien cuu\Du-an-A-Quy-trinh-son\anh_vao'
os.makedirs(D, exist_ok=True)

# lo anh gui luc 21:57 hom nay
files = [f for f in os.listdir(CACHE) if f.startswith('img_') and abs(os.path.getmtime(os.path.join(CACHE, f)) - time.mktime(time.strptime('2026-10-05 21:57', '%Y-%m-%d %H:%M'))) < 300]
files.sort(key=lambda f: os.path.getmtime(os.path.join(CACHE, f)))
print('lo anh 21:57:', len(files), 'file')

seen = {}
i = 0
for f in files:
    p = os.path.join(CACHE, f)
    h = hashlib.md5(open(p, 'rb').read()).hexdigest()
    if h in seen:
        print('  trung md5, bo qua:', f, '(= %s)' % seen[h])
        continue
    i += 1
    seen[h] = f
    dst = os.path.join(D, 'anh_%02d.jpg' % i)
    shutil.copy2(p, dst)
    print('  -> %s  (%d byte, tu %s)' % (os.path.basename(dst), os.path.getsize(dst), f))
print('tong anh trong anh_vao:', len([f for f in os.listdir(D) if f.lower().endswith('.jpg')]))
