Reputation: 57
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")
The code above executes with out an error, its added to job queue but callback is not called.
while if i change run_once to run_daily, it works perfectly fine
ieupdater.job_queue.run_daily(bot_bal,bot_refresh_time,name="daily_check_task")
or
if the time zone is "None"(tzinfo=None) in above code then, run_once work perfectly fine, so i thought the problem is with time zone, but if that's the case then run_daily shouldn't work because they both use datetime.time for time in syntax
syntax for job queue run_once for python telegram bot.
syntax for job queue run_daily for python telegram bot.
Any suggestions or answers would be helpful. i'm just beginner in coding :)
EDIT:
run_once works but instead of setting the given time as the timezone(bot_refresh_time=bot_refresh_time.replace(tzinfo = tz)
), it converts the time to the given timezone (ie if my timezone is Asia/Kolkata and the given time is 01:00AM, while using using run_once the job executes at 06:30AM IST instead of 01:00AM IST). This problem only occurs when using run_once, there is no problem with run_daily
Upvotes: 0
Views: 1650
Reputation: 7050
As of version 13.0, JobQueue
can only handle pytz
timezones, as PTB uses the library APScheduler for the JobQueue
. Note that older versions are no longer supported. A working example for run_once
would be:
import datetime as dtm
import pytz
from telegram.ext import Updater
updater = Updater('TOKEN')
def test(_):
print('running at', dtm.datetime.utcnow())
time = pytz.timezone('Asia/Kolkata').localize(dtm.datetime.now() + dtm.timedelta(seconds=5))
updater.job_queue.run_once(test, time, name="daily_check_task")
updater.start_polling()
updater.idle()
Upvotes: 1