parse_saby/app/scheduler.py

20 lines
835 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
import subprocess
def run_parser(filename = 'main.py'):
print(f"Запуск {filename}...")
subprocess.run(['python', filename])
def launch_the_scheduler(h=6, m=0):
scheduler = BlockingScheduler() # Создание планировщика
# Каждый день в 6:00 утра запуск run_parser()
scheduler.add_job(run_parser, trigger=CronTrigger(hour=h, minute=m))
print("Планировщик запущен. Нажмите Ctrl+C для остановки.")
try:
scheduler.start()
except KeyboardInterrupt:
print("Планировщик остановлен")
except Exception as e:
print("Не непредвиденная ошибка: ", e)