0

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)```
  • Does this answer your question? [How do I get a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python) – Random Davis Dec 02 '20 at 21:33

1 Answers1

1

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)
bkakilli
  • 498
  • 6
  • 12
  • Hello, thanks for the answer, it really helped me, but can I make it do it's for the whole month. and not have to change it every day. Thanks! – Josh Brown90 Dec 02 '20 at 22:02
  • You don't have to change it everyday. As long as it runs, it will call your function at the same time everyday. You can set a limit datetime for the program to run. Right now it runs forever with "while True". Just change it to something like "while now <= limit_date". – bkakilli Dec 02 '20 at 22:49