简体   繁体   English

如何使用另一个 python 文件在一周中的某些日子运行 python 文件?

[英]How to run a python files on Certain days of the week using another python file?

I am building a program in Python which will help me to join my online classes on time.我正在 Python 中构建一个程序,这将帮助我按时加入我的在线课程。 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.现在,我想创建一个 python 文件,它将检查是星期一还是星期二或星期三或星期四或星期五,然后运行为当天创建的文件。 For example in monday it should run mon.py and so on.例如在星期一它应该运行 mon.py 等等。 How can I do this?我怎样才能做到这一点?

It may help you.它可能会帮助你。
First, Make sure that all python file are in the same directory.(like this)首先,确保所有 python 文件都在同一个目录中。(像这样)

Online_class:在线课程:

check.py检查.py
mon.py mon.py
tue.py周二.py
... ...
fri.py易碎的


check.py检查.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")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM