简体   繁体   English

如何让 Python 每天在特定时间运行并每小时重复一次?

[英]How can I make Python run at a specific time everyday and make it repeat every hour?

I made a Python script to remind me to drink water every hour.我做了一个 Python 脚本来提醒我每小时喝水。 My code is:我的代码是:

import time
import plyer
from plyer import notification

if __name__ == "__main__":
    while True:
        plyer.notification.notify(
            title="Go and Drink Water!",
            message="You need to drink at least 3.5 litres of water Everyday. Being Dehydrated can decrease Brain Function and Energy levels.",
            app_icon="C:\\Users\\(My username)\\(location of icon)",
            timeout=10,
        )
        time.sleep(60 * 60)

I put the python path and this script's path in a.bat file and made it run everyday at 8:35am using Task Scheduler.我将 python 路径和此脚本的路径放在 a.bat 文件中,并使用任务计划程序使其每天早上 8:35 运行。 It did run at 8:35am but it didn't repeat.它确实在上午 8 点 35 分运行,但没有重复。 Can anyone point out what I am doing wrong or suggest a better method?谁能指出我做错了什么或提出更好的方法?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作一个 cron.yaml 文件以每小时运行一次 python 脚本,用于谷歌云应用引擎 - How can I make a cron.yaml file to run python script every hour for google cloud app engine 如何让机器人每天在特定时间在 discord.py 中运行定义的函数? - How to make the bot run a defined function at a specific time everyday in discord.py? 如何让我的函数每小时运行一次? - How to make my function run every hour? 如何让python脚本在特定时间运行? - How to make python script to run at specific time? 如何使用 python 让 Discord 机器人每天在特定时间运行 function? - How to make Discord bot run a function every day at a specific time using python? 我怎样才能使系统时间在 Python 中运行得更快? - How can i make the system time run faster in Python? 如何安排 Python 脚本在每天的特定时间运行,并使其成为 AWS Elastic Beanstalk 应用程序 zip 文件的一部分? - How can I schedule a Python script to run at a particular time every day, and make it a part of AWS Elastic Beanstalk application zip file? 如何每天使用调度程序同时运行python脚本? - How do I run python script everyday at the same time with scheduler? 如何使 function 重复,直到使用 pynput 在 python 上按下特定键? - How can I make a function repeat until a specific key is pressed on python with pynput? (discord.py) 如何让机器人在每天的固定时间自动更改特定用户的昵称? - (discord.py) How do I make it so that the bot automatically changes a specific user's nickname at a fixed time everyday?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM