[英]Python script to run a function at a specific time every day does not work when deployed on Heroku
I am trying to create a telegram bot using python that will run a function every day at a specific time.我正在尝试使用 python 创建一个电报机器人,它将每天在特定时间运行一个函数。
from operator import ge
import schedule
import telebot
import time
from threading import Thread
from time import sleep
bot = telebot.TeleBot("bot token")
jay = chat_id
def test_message():
bot.send_message(jay, "This is test")
def schedule_checker():
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == "__main__":
# Create the job in schedule.
schedule.every().day.at("03:58").do(test_message)
Thread(target=schedule_checker).start()
It works when I run it via my terminal on VScode, but when I deploy the bot on Heroku, it doesn't work.当我通过终端在 VScode 上运行它时,它可以工作,但是当我在 Heroku 上部署机器人时,它不起作用。 I am pretty sure I deployed it correctly.
我很确定我正确地部署了它。 Would appreciate any advice, thank you in advance and apologise if this is a dumb question (I am just starting my coding journey).
如果这是一个愚蠢的问题(我刚刚开始我的编码之旅),将不胜感激任何建议,提前感谢您并道歉。
I realised the bot deployed on Heroku was still sending messages, but it posted at the wrong timings.我意识到部署在 Heroku 上的机器人仍在发送消息,但它在错误的时间发布。 I realised that it was using UTC time.
我意识到它使用的是UTC时间。 I edited the code to change it to UTC time and it now posts at the correct timings.
我编辑了代码以将其更改为 UTC 时间,现在它在正确的时间发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.