0
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

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It is still an issue in version 13.5. Wrapping pytz.timezone('<timezone>').localize( ) around my datetime-object fixed run_once! Btw. the timezones can be listed using pytz.all_timezones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.