Right now I have some scripts I want to run automatically and periodically, say, every two days.
The way I've structured looks something like this.
Script1:
def example1():
#Some Selenium code
example1()
Script2:
def example2():
#Some more Selenium code
example2()
Script3:
import Script1
import Script2
As you'll notice, 'Script1' and 'Script2' already call their main function, so in 'Script3' I only need to import the scripts, and not call the functions (although this works for me, I'm not sure whether this is a safe approach/good practice).
My question: if I use schedule to run 'Script3' every x days, will this mean the script will run forever, or does it run once every x days and then goes into sleep mode until it has to run again? Also, for it to run it would requiere the PC to be always on, right?
If so, is there any way to make it run automatically and periodically even with the PC turned off?
Thanks in advance!
I'm not sure whether this is a safe approach/good practice
The Zen of Python says; "Explicit is better than implicit." So it is better to use:
import script1
import script2
script1.example1()
script2.example2()
It is generally not recommended for a module to run code on import. Importing a module should preferably not have side effects.
if I use schedule
There are probably more than one program named "schedule". Can you be more specific?
is there any way to make it run automatically and periodically even with the PC turned off
There are more than one way to run a script periodically. UNIX-like systems such as Linux have cron
and atrun
.
Other systems have their own way.
But all of those only work when the machine is on. Turning a machine on at regular intervals is generally not possible on a PC without extra hardware. Unless you can get the Intel Management Engine to do your bidding.
Microcontrollers such as the ESP32 (which can run micropython
) do have a "deep-sleep" mode for this purpose but I kind of doubt they can run selenium. :-)