-1

I am building a program in Python which will help me to join my online classes on time. I have several files of the monday classes - friday classes. The code I wrote for the days are like this:

import schedule
import time
import webbrowser
import keyboard
from time import sleep

def computer():
    webbrowser.open('zoom_link_for_class')
    sleep(3)
    keyboard.press('tab')
    sleep(0.2)
    keyboard.press('tab')
    sleep(0.2)
    keyboard.press('enter')
    sleep(7)
    keyboard.write('224455')
    sleep(0.1)
    keyboard.press('enter')
    
def english():
    webbrowser.open('englishclasszoomlink')
    sleep(3)
    keyboard.press('tab')
    sleep(0.2)
    keyboard.press('tab')
    sleep(0.2)
    keyboard.press('enter')
    sleep(7)
    keyboard.write('224455')
    sleep(0.1)
    keyboard.press('enter')

schedule.every().monday.at("08:40").do(computer)
schedule.every().monday.at("11:41").do(english)


while True:
    schedule.run_pending()
    time.sleep(1)

Now, I want to create a python file, which will check if it is Monday or Tuesday or Wednesday or Thursday or Friday, and then run the file created for the day. For example in monday it should run mon.py and so on. How can I do this?

Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
  • 2
    What OS are you using? If you do not specifically need to use Python to launch it could you use cron jobs (Linux) or scheduled tasks (Windows)? https://stackoverflow.com/questions/1603109/how-to-make-a-python-script-run-like-a-service-or-daemon-in-linux – 3therk1ll Jan 25 '22 at 11:35
  • I'm using windows – KrishTheCoder756 Jan 25 '22 at 11:46
  • I would just use scheduled tasks to run the script on the given days – 3therk1ll Jan 25 '22 at 11:51

1 Answers1

-1

It may help you.
First, Make sure that all python file are in the same directory.(like this)

Online_class:

check.py
mon.py
tue.py
...
fri.py


check.py

from datetime import datetime
import os
weekday = datetime.today().strftime('%A')
if weekday=="Monday":
    os.system("python mon.py")
elif weekday=="Tuesday":
    os.system("python tue.py")
#...
else:
    os.system("python fri.py")

monstar
  • 1
  • 2
  • This doesn't solve the issue of having to have a daemon of some kind that runs in the background and initiates the OPs script. For this answer to work in it's current state it would itself need a scheduling service or script running as a daemon or similar – 3therk1ll Jan 25 '22 at 12:04
  • Thanks mate it worked – KrishTheCoder756 Jan 25 '22 at 12:16