# -*- coding: utf-8 -*-
"""Gom album ảnh chủ nhân gửi qua Telegram (cache) → QC\images\_loc_0810\ + khử trùng md5."""
import glob, hashlib, os, shutil, time

SRC = os.path.join(os.environ['LOCALAPPDATA'], 'hermes', 'cache', 'images')
DST = r'C:\Claw 2\QC\images\_loc_0810'
os.makedirs(DST, exist_ok=True)

# lô mới nhất = 4 ảnh có mtime 08/10 21:26 (album chủ nhân gửi)
files = sorted(glob.glob(os.path.join(SRC, 'img_*.jpg')), key=os.path.getmtime, reverse=True)
moi = [f for f in files if time.strftime('%d/%m %H:%M', time.localtime(os.path.getmtime(f))) == '08/10 21:26']
print('ảnh trong lô album 08/10 21:26:', len(moi))
seen, n = {}, 0
for f in sorted(moi, key=os.path.getmtime):
    h = hashlib.md5(open(f, 'rb').read()).hexdigest()
    if h in seen:
        print('   bỏ (trùng md5):', os.path.basename(f), '=', seen[h]); continue
    seen[h] = os.path.basename(f)
    n += 1
    d = os.path.join(DST, 'loc_0810_%02d.jpg' % n)
    shutil.copy2(f, d)
    print('   %s  →  %s   (%d byte)' % (os.path.basename(f), os.path.basename(d), os.path.getsize(d)))
print('đã gom', n, 'ảnh duy nhất vào', DST)
print('thư mục:', sorted(os.listdir(DST)))
