"""
DEWA PR Tracker — Scheduler
Runs the scraper automatically every day at 08:00 AM.

Run:  python scheduler.py
"""
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
from datetime import datetime

from scraper import run_scrape


def job():
    print(f"\n[scheduler] {datetime.now().isoformat()} — Starting scheduled scrape…")
    run_scrape()
    print(f"[scheduler] Scrape complete.")


if __name__ == "__main__":
    scheduler = BlockingScheduler(timezone="Asia/Dubai")
    scheduler.add_job(job, CronTrigger(hour=8, minute=0))
    print("[scheduler] Started — scraper will run daily at 08:00 Asia/Dubai time.")
    print("[scheduler] Press Ctrl+C to stop.")
    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        print("[scheduler] Stopped.")
