我需要让我的调度程序在每X天的特定时间启动(例如,每7天的11:30)
我的代码:
def make_interval(record_date: str, record_time: str, record_title: str):
hours, minutes = _get_hours_minutes(record_time)
trigger = AndTrigger([IntervalTrigger(days=int(record_date)),
CronTrigger(hour=hours, minute=minutes)])
scheduler.add_job(_send_notification, trigger=trigger,
kwargs={...},
id=record_title,
timezone=user_timezone)
但我得到了错误:第三行的[Errno 22] Invalid argument
。
怎么了?不知道为什么不管用
_get_hours_minutes(仅从"HH:MM"中分别返回小时和分钟的值)
def _get_hours_minutes(user_time: str) -> (str, str):
return user_time[:2], user_time[3:5]
回溯:
Traceback (most recent call last):
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\scheduler\main.py", line 92, in make_interval
scheduler.add_job(_send_notification, trigger=trigger,
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\schedulers\base.py", line 447, in add_job
self._real_add_job(job, jobstore, replace_existing)
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\schedulers\base.py", line 863, in _real_add_job
replacements['next_run_time'] = job.trigger.get_next_fire_time(None, now)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\triggers\combining.py", line 55, in get_next_fire_time
fire_times = [trigger.get_next_fire_time(previous_fire_time, now)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\triggers\combining.py", line 55, in <listcomp>
fire_times = [trigger.get_next_fire_time(previous_fire_time, now)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\triggers\interval.py", line 68, in get_next_fire_time
return normalize(next_fire_time)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pizhlo21\Desktop\Folder\python\tg_bot_reminder\venv\Lib\site-packages\apscheduler\util.py", line 431, in normalize
return datetime.fromtimestamp(dt.timestamp(), dt.tzinfo)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument
我的操作系统平台: windows 10
1条答案
按热度按时间gblwokeq1#
我想仔细看看“record_time”和传递给“_get_hours_minutes”的格式。它必须是“HH:MM”格式(假设Errno 22错误是针对该行的。还有其他方法可以使用datetime库,这样就不必对字符串进行切片。