【发布时间】:2021-04-03 10:40:20
【问题描述】:
y=str("12:50AM")+"+0000"
bot_refresh_time = datetime.strptime(y,'%I:%M%p%z').timetz()
bot_refresh_time=bot_refresh_time.replace(tzinfo = tz)
updater.job_queue.run_once(bot_bal,bot_refresh_time,name="daily_check_task")
上面的代码执行没有错误,它被添加到作业队列但没有调用回调。
如果我将 run_once 更改为 run_daily,它可以正常工作
即updater.job_queue.run_daily(bot_bal,bot_refresh_time,name="daily_check_task")
或
如果上述代码中的时区为“None”(tzinfo=None),那么 run_once 工作得非常好,所以我认为问题出在时区上,但如果是这种情况,那么 run_daily 不应该工作,因为它们都使用 datetime.time 作为语法中的时间
python电报机器人的作业队列run_once的语法。
python电报机器人的作业队列run_daily的语法。
任何建议或答案都会有所帮助。我只是编码的初学者:)
编辑:
run_once 有效,但不是将给定时间设置为时区 (bot_refresh_time=bot_refresh_time.replace(tzinfo = tz)),而是将时间转换为给定时区(即,如果我的时区是亚洲/加尔各答,给定时间是 01:00AM ,在使用 run_once 时,作业在 IST 上午 06:30 而不是 IST 上午 01:00 执行)。这个问题只在使用run_once时出现,run_daily
【问题讨论】:
标签: python telegram-bot python-telegram-bot telegram-api