Run python script everyday to open and execute a program - python

Is it possible for a python script to open and execute a program each day at a specific time? My attention is...poor, but I installed a productivity program (FocalFilter) which blocks unproductive websites. Could a python script be written where it opens this program and runs it so the sites are blocked as soon as I get to my computer in the morning?
Does it matter if the computer is in locked mode (Windows 10)? I don't need a script or anything, it can be a fun little project, but I just don't know if it is even possible.

Yes, indeed you can use python. But the operating system(s) do it for you now.
Scheduled tasks run even if the computer is locked.
Take look at this:
https://ss64.com/nt/schtasks.html
or look att the Scheduler in Administration tools in Control panel. There you have many cool options.
Also, if you permanently want to block certain sites, like facebook.com and stackoverflow.com you can edit your hosts file so that facebook.com goes to 127.0.0.1, i.e. your own computer. Antiviruses do this too. Read here:
https://support.rackspace.com/how-to/modify-your-hosts-file/

Related

Run python script after PLC performed an action

I try to do an automation using a python script and Snap7 to connect windows pc to PLC Siemens7-1200.
They script itself does a procession of an image and saving that image afterwards and it is working as it should. My next step is to include an automation. I want this script to always run, when PLC performed a specific action. After doing that action the PLC gives out a specific signal '1' for 3 seconds.
My first idea was to connect to PLC in my python script via Snap7 (this already works) and having a While loop that always checks this signal and an IF statement. And IF the signal is '1', the rest of the python script should run, take image, process image etc.
I wondered whether this idea is useful or whether there may be an easier solution? If i have the While loop the script will be active all the time. I wondered whether there is an option to run the script only after this action was performed by PLC to not have the script active all the time. All the time is actually 24/7
In other words: Whats the easiest way to run a python script from a windows PC when a connected PLC performed a specific action?

Python program should still run even when system sleeps [Uuntu]

I'd like to keep my Python program running, even when my computer is sleeping. The python program should not stop even when the system sleeps.
I am using a Ubuntu.
My file is only on my computer, not online.
Please help me out to achieve this.
If you need more information, please leave a comment!
Short Answer -
No! you can't.
Details -
Sleep Mode is a power-saving state that is similar to pausing a DVD movie, all applications on the computer are suspended and there is no setting to change this. If you set the machine to sleep, then all programs are suspended. Sleep mode and hibernation both simply save the state your desktop is in (what programs are open, what files are accessed) in a file that is saved in RAM or on the hard drive respectively. But the computer is then put into a low power state.

Make Python script run automatically + SQL database

I have done many research on the forum but I didn't find a clear answer to my question.
I have created a python code which extracts data from a website and put it in a SQL database (with SQLITE).
Now, I would like to make it run 24 hours a day on a server so that it collects data at each moment.
Although I know how to code, I don't have a broad knowledge of IT in general.
Would you know by chance how to solve my problem ?
Edit: I was more thinking about putting my scripts on a cloud server to make it run instead of running it directly from my pc.
Thank you very much.
Lcs
I can think of two options:
1) You use a simple "while true" and "wait" in python, so the script is running constantly.
import time
while True:
# Code
time.sleep(5) # goes to sleep for 5 seconds
You can also do this in shell script (infinite loop+sleep) and then run the program when you want.
2) You can use cronjobs to run the pytho script. You basically have the script the will scrap the website and it will be launched every X seconds/minutes/hours. You can read more about how to use cronjobs in Google
Depends on what system you are using (Unix or windows) you can use either:
1. Windows Task Scheduler for Windows
2. Crontab for Unix

Does Selenium Python execute a program as scheduled in Windows or not?

I am not sure how to phrase this question (does a tree falling in the forest make a sound if there's no one there to hear it?) but I have a simple program that visits several websites through a selenium loop, opening each url in a new tab.
I know the program works fine when I execute it and watch it work. When that happens, the program opens the tabs as instructed, then leaves them open for me to check that everything worked fine, then it sends me an email to let me know that the program has run.
Now my problem is that I have scheduled this task in Windows, and I receive the email when the program executes, but when this happens and I check my browser I don't see any tabs left open, as I usually see after the program has run.
So my question is/are: does Selenium have some code-only mode that executes the programs in the background and goes to the places I indicated it to go, without opening the tabs if I am not using the browser at the time? Could it be possible that the program is running and reaching the end -thus sending me the email- but did not open the tabs and thus it is not working when I schedule it to work and I am not at the computer or the computer is on standby (I have scheduled it to wake the computer to execute the program)
Is there anything I am missing? Thanks!

How to put a PC into sleep mode using python?

While the copy is in progress, can we put a PC into sleep mode for a specific period of time, then wake up and continue copy using python script? Can you please share the code?
Actually this is possible using shell script.
Most machines manufactured after 2000 support real-time clock wakeup. There are many reasons to do so, one of which would be to record a TV program at a certain time. See ACPI Wakeup.
You'll have to explain what you mean by "While the copy is in progress" - there's not much to go on in the question. While OS drivers have suspend/resume functions, I don't know how to tell the python interpreter to save its state in the middle of running a script and then resume after wakeup. It's possible that the OS suspend/hibernate would fully capture the state of a copy operation and resume without a hiccup, but I wouldn't trust it to do so without substantial testing.
If you have "Wake On Lan" enabled you could potentially run a python script on a different PC and trigger the wake up after your specific period of time.
The scripts would probably need to talk to each other, unless you just do it all at times set in advance.

Categories

Resources