1

I've created a python code that automatically join zoom classes at a specific time using the schedule module. This is an example code below:

schedule.every().monday.do(join_zoom)

Is there a way that i can run the code like this

date = "monday"
schedule.every().[date].do(join_zoom)

Thanks

Bach Tran
  • 53
  • 5

2 Answers2

0

Sure, a simple if-else statement will do:

date = "monday"

if date == "monday":
    schedule.every().monday.do(join_zoom)
elif date == "tuesday":
    schedule.every().tuesday.do(join_zoom)

etc.

RJ Adriaansen
  • 7,587
  • 2
  • 8
  • 22
0

Sure, getattr is what you're looking for:

date = "monday"
getattr(schedule.every(), date).do(join_zoom)

If you want, you can try it out with this self-built snippet:

class Schedule:

    @staticmethod
    def every():
        return Day

class FooBar:

    @staticmethod
    def do(stringg):
        print('success')

class Day:
    monday = FooBar
    tuesday = FooBar


schedule = Schedule
getattr(schedule.every(), 'monday').do('ciao')
scandav
  • 690
  • 7
  • 19