#!/usr/bin/env python3
"""
Invia su Telegram i file Talent Risk più recenti.
Chiamato dal cron ogni sera alle 20:00.
"""
import os, sys
sys.path.insert(0, os.path.expanduser('~/.hermes/scripts'))

HOME = os.path.expanduser('~/.hermes')
LATEST_LINK = os.path.join(HOME, 'backups', 'talent-risk', 'latest')

if not os.path.islink(LATEST_LINK):
    print("[ERR] Nessun backup trovato")
    sys.exit(1)

latest = os.path.realpath(LATEST_LINK)
files = [f for f in os.listdir(latest) if f.endswith(('.xlsx', '.docx', '.json'))]

if not files:
    print("[ERR] Nessun file nel backup latest")
    sys.exit(1)

print(f"[OK] Backup latest: {latest}")
for f in files:
    fpath = os.path.join(latest, f)
    fsize = os.path.getsize(fpath)
    print(f"  {f} ({fsize} byte) — MEDIA:{fpath}")
