#!/usr/bin/env python3
"""Cron script: refresh Qualys agents data every 6h"""
import sys
sys.path.insert(0, "/opt/patchcenter")

from app.database import SessionLocal, SessionLocalDemo
from app.services.qualys_service import refresh_all_agents

for factory, name in [(SessionLocal, "prod"), (SessionLocalDemo, "demo")]:
    try:
        db = factory()
        result = refresh_all_agents(db)
        print(f"[{name}] {result.get('msg', result)}")
        db.close()
    except Exception as e:
        print(f"[{name}] ERROR: {e}")
