#!/usr/bin/env python3 """Verify schedules are now interpreted correctly with Unix day-of-week""" import sys sys.path.insert(0, r'C:\PYTHON\Scheduler') from core.database import SchedulerDatabase from core.cron_utils import convert_unix_to_iso_dayofweek from apscheduler.triggers.cron import CronTrigger from datetime import datetime import pytz import json db = SchedulerDatabase() schedules = db.get_all_schedules(enabled_only=True) print("=== SCHEDULE VERIFICATION WITH UNIX DAY-OF-WEEK ===\n") for s in schedules: if s['schedule_type'] != 'cron': continue config = json.loads(s['schedule_config']) if isinstance(s['schedule_config'], str) else s['schedule_config'] cron_expr = config.get('cron', '') print(f"Schedule: {s['name']}") print(f" Target: {s.get('target_name', 'N/A')}") print(f" Original cron: {cron_expr}") # Convert and show what APScheduler will use cron_expr_iso = convert_unix_to_iso_dayofweek(cron_expr) print(f" Converted to ISO: {cron_expr_iso}") try: trigger = CronTrigger.from_crontab(cron_expr_iso, timezone=pytz.timezone('Europe/Rome')) now = datetime.now(pytz.timezone('Europe/Rome')) # Get next 3 executions next_times = [] current = now for i in range(3): next_time = trigger.get_next_fire_time(None, current) if next_time: next_times.append(next_time) current = next_time else: break if next_times: print(f" Next executions:") for nt in next_times: day_name = nt.strftime('%A') print(f" {nt.strftime('%Y-%m-%d %H:%M')} ({day_name})") else: print(f" No next executions found") except Exception as e: print(f" ERROR: {e}") print()