在 Python 到 运行 每小时安排一个简单的通知脚本

Scheduling a simple notification script in Python to run every hour

我是 Python 的新手。

我刚刚编写了这个在我的桌面上打印一条消息的简单脚本:

from plyer import notification
notification.notify(
title="HI MATTEO!",
message="Here's the notification to be sent every hour!",
timeout=10
)

Here's the screenshot of the notification

我想知道是否有办法运行每小时(或在给定时间)

发送此通知

非常感谢

马泰奥·福萨蒂

您应该查看 schedule 软件包 (https://pypi.org/project/schedule/)。

然后,运行 类似于:

schedule.every().hour.do(my_notification)
...
while True:
  schedule.run_pending()
  time.sleep(1)