简体   繁体   English

如何在python每天特定时间运行一个function?

[英]How to run a function every day at a specific time in python?

So, here is what I've been trying to do.所以,这就是我一直在尝试做的事情。 I'm making a little program that goes to my classes on time so I don't miss them.我正在制作一个按时上课的小程序,这样我就不会错过他们。 And I have problems with the most important part... The automation: This is my code:我在最重要的部分遇到了问题......自动化:这是我的代码:

from pyautogui import *
import pyautogui
import keyboard
from pynput.keyboard import Key, Controller
import webbrowser

pos = pyautogui.position()
print(pos)

def open_b():
    pyautogui.click(248, 754)
    url='https://myclass.com'
    webbrowser.open_new_tab(url)```

A straightforward solution would be:一个简单的解决方案是:

import time
import datetime

# Enter the first class date and time
class_time = datetime.datetime(year, month, day, hour=13, minute=30, second=0)

delta = datetime.timedelta(days=1)
while True:
    
    if datetime.datetime.now() >= class_time:
        your_function()
        class_time += delta

    # Depending on need, check frequency can be decreased
    time.sleep(1)

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

相关问题 如何每天在特定时间运行python函数 - How to run a python function every day at specific time 如何使用 python 让 Discord 机器人每天在特定时间运行 function? - How to make Discord bot run a function every day at a specific time using python? Python:如何自动化脚本在特定时间每天运行? - Python: How to automate script to run every day at specific time? 在 Heroku 上部署时,每天在特定时间运行函数的 Python 脚本不起作用 - Python script to run a function at a specific time every day does not work when deployed on Heroku Discord.py Bot 每天特定时间运行功能 - Discord.py Bot run function at specific time every day 如何安排python脚本在特定时间每天运行? (Windows计划除外) - How can I Schedule python script to run every day at specific time ? (except Windows schedule) 如何安排代码在每天的特定时间运行? - How to schedule code to run at a specific time every day? 如何在每天的特定时间持续运行Google合作实验室? - How to constantly run Google Colaboratory at a specific time every day? 如何安排生产 python 脚本以触发 function 在每天的指定时间运行 - How to schedule a production python script to trigger a function to run at a specified time every Day python-如何在每个月的最后一天运行功能? - python - how to run a function on last day of every month?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM