Search code examples
pythonschedule

I want to make a type bot which will join my classes automatically i have tried it but got the error


I want to make a type bot which will join my classes automatically i have tried it but got the error

Importing All the modules Needed

import schedule
import webbrowser
import pyttsx3
import timetable
import time

Join Class Function for joining classes

def joinclass(classname):
    zoomlinks=timetable.zoomlinks
    webbrowser.open(zoomlinks[classname])
    pyttsx3.speak(f"joining {classname}")

Monday's code for joining classes

schedule.every().monday.at("08:30").do(joinclass("Assembly"))
schedule.every().monday.at("08:40").do(joinclass("Hindi"))
schedule.every().monday.at("09:30").do(joinclass("Elit"))
schedule.every().monday.at("10:05").do(joinclass("Maths"))
schedule.every().monday.at("11:15").do(joinclass("History"))
schedule.every().monday.at("12:05").do(joinclass("PT"))

Tuesday's code for joining classes

schedule.every().tuesday.at("08:30").do(joinclass("Assembly"))
schedule.every().tuesday.at("08:40").do(joinclass("Maths"))
schedule.every().tuesday.at("09:30").do(joinclass("Geography"))
schedule.every().tuesday.at("10:05").do(joinclass("Biology"))
schedule.every().tuesday.at("11:15").do(joinclass("Physics"))
schedule.every().tuesday.at("12:05").do(joinclass("Gk"))

Wednesday's code for joining classes

schedule.every().wednesday.at("08:30").do(joinclass("Assembly"))
schedule.every().wednesday.at("08:40").do(joinclass("Hindi"))
schedule.every().wednesday.at("09:30").do(joinclass("Elit"))
schedule.every().wednesday.at("10:05").do(joinclass("Telugu"))
schedule.every().wednesday.at("11:15").do(joinclass("Chemistry"))
schedule.every().wednesday.at("12:05").do(joinclass("Elang"))

Thursday's code for joining classes

schedule.every().thursday.at("08:30").do(joinclass("Assembly"))
schedule.every().thursday.at("08:40").do(joinclass("Geography"))
schedule.every().thursday.at("09:30").do(joinclass("Maths"))
schedule.every().thursday.at("10:05").do(joinclass("Telugu"))
schedule.every().thursday.at("11:15").do(joinclass("Chemistry"))
schedule.every().thursday.at("12:05").do(joinclass("Elang"))

Friday's code for joining classes

schedule.every().thursday.at("08:30").do(joinclass("Assembly"))
schedule.every().thursday.at("08:40").do(joinclass("Elang"))
schedule.every().thursday.at("09:30").do(joinclass("Maths"))
schedule.every().thursday.at("10:05").do(joinclass("Computer"))
schedule.every().thursday.at("11:15").do(joinclass("History"))
schedule.every().thursday.at("12:05").do(joinclass("Biology"))

To Run join the pending classes

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

I got an Error like this:-

self.job_func = functools.partial(job_func, *args, **kwargs) TypeError: the first argument must be callable


Solution

  • Basically, you're calling the functions like this:

    schedule.every().monday.at("08:30").do(joinclass("Assembly"))
    #                                      ^^^^^^^^^^^^^^^^^^^^^
    

    when you should call them like this:

    schedule.every().monday.at("08:30").do(joinclass, "Assembly")
    #                                      ^^^^^^^^^^^^^^^^^^^^^
    

    Off-topic, but you can simplify your code using dictionaries:

    frame = {
        'monday': {
            '08:30': 'Assembly',
            '08:40': 'Hindi',
            '09:30': 'Elit',
            '10:05': 'Maths',
            '11:15': 'History',
            '12:05': 'PT',
        },
        'tuesday': {
            '08:30': 'Assembly',
            '08:40': 'Maths',
            '09:30': 'Geography',
            '10:05': 'Biology',
            '11:15': 'Physics',
            '12:05': 'Gk',
        },
        # Do the same for all the weekdays
    }
    

    Then, using the above dictionary (frame), you can run all schedules using this code:

    for weekday, frame_schedule in frame.items():
        for time, subject in frame_schedule.items():
            getattr(schedule.every(), weekday).at(time).do(joinclass, subject)