Execute script in background "from" Python 3 programmatically, on Ubuntu? - python

Is possible to launch a script in background FROM ANOTHER PYTHON SCRIPT?
I have one script: awesome.py .This must be executed every minute
But it must be launched from a UI python script (miniApp.py) on click button, this is the function:
def startScript(self,e)
//code to launch awesome.py script in background and repeat every minute
How can I do this?

Related

Why is this Python automation script not working?

I wrote a python script to automate content recordings in AdobePremiere Pro. It is supposed to be triggered by tasks created on Windows' Task Scheduler. But it is not working as intended.
It seems like the commands expected are not being sent for some reason.
This is the link to the repository containing all the logic tried to achieve the automation task:
https://github.com/rfabreu/AdobePremiere-Recording-Automation-Python
After writing the python scripts, the batch scripts were created to execute those python files.
Then on the Task Scheduler, tasks were created to run the required batch scripts.
Python script to start a recording:
import schedule
import time
from pynput import keyboard
def start_recording():
with keyboard.Press(keyboard.Key.g):
keyboard.press(keyboard.Key.g)
keyboard.release(keyboard.Key.g)
schedule.every().day.at("18:50").do(start_recording)
while True:
schedule.run_pending()
time.sleep(1)
Batch script to run the python scripts when triggered:
#echo off
cd [enter_dir_name]
set PYTHON_EXE=python
set SCRIPT_DIRECTORY=.
for %%f in (%SCRIPT_DIRECTORY%\*.py) do (
start /B /MIN %PYTHON_EXE% "%%f"
)
The expected result is that the script sends keyboard commands at a certain time:
So, considering that AdobePremiere Pro is open, the first script should send a key press command of the "g" key to start recording when triggered by the bat file.
Then, when triggered at a certain time another script should send the key press command of the "esc" key to stop recording.
The final step if for the third script to send a key press command of the "enter" key to save the recorded content.
After trying different things, including updating python on the pc, nothing happens.
When checking the Task Scheduler logs it seems like the task to run the bat file was executed successfully, but then the desired outcome did not reflect any effects on AdobePremiere Pro.

How to re-enable notifications for python after disabling it in windows?

I made a simple python program to show a system notification and I decided to disable notifications for python for some time and enable it again afterwards in Windows settings > System > Notifications & Actions, however python was not in the list of apps that show notifications.
HOW DO I ENABLE IT AGAIN?
Is possible to do it with the code itself or with command prompt or by any other means?
Code:
from win10toast import ToastNotifier
notif = ToastNotifier()
notif.show_toast("ALERT", "TEST1", icon_path="C:/Windows/SystemApps/Microsoft.Windows.SecHealthUI_cw5n1h2txyewy/Assets/Device.contrast-white.ico", duration=5)
6 Steps to solve this problem:
1 - Open both Settings > System > Notifications & Actions and wherever you run your program (Example - Terminal or IDE)
2 - Increase the time of the notification to be shown by python to a large number like 50 seconds, by changing the duration argument in *.show_toast()
3 - Run your script and quickly refresh the app list found in the Settings window you
opened in step 1 by going to another tab such as Sound and coming back to the previous tab
4 - Now that your program is running and trying to display a notification, Python will be added to the list in until the time duration is elapsed, quickly turn on Python just like how you would for any other app.
5 - Close settings and terminate your script.
6 - Run your script again and the notification you were trying to display should now come as usual.

running a python script from startup to shutdown

I am using python 3. On windows 7.
I recently made a python keylogger. It saves the keylogs in a text file as i type and upon pressing WIDOWS Key it sends the text from the textfile to my gmail account using smtplib.
I have to manually start the python file and it gets quite boring!
What my question is that is there any way to run that keylogger script on startup (without manually putting it in the startup folder -- because i want the script to do everything itself), and then to quickly close the script as soon as the user presses the shutdown button (and delay the shutdown time somehow).
The reason i want this is because i belive that a keylogger must be hidden from the user not to include that it must be hidden from the antivirus ;)
i have tested this with python task scheduler but it only takes time parameters (i.e. from 5:00 to 7:00) not the startup and shutdown time.
If i am to include more information on this topic that you need to solve this question i will gladly help you!
Thanks in advance

Run a script repeatedly and externally from Flask

Imagine you are measuring the distance of something with a Raspberry Pi. You have a nice python script which measures the distance via a sensor and returns a variable.
Imagine you would like to automate the process and view the results on a web page created with Flask. Basically, be able to turn it on and have it run once a minute regardless of whatever else you do in that web page or anywhere else on the "website".
Graphically:
click a button on a web page -> Script starts -> Script runs once a minute, regardless of whether you close the page, navigate to another page, etc.
How would you go about it?
Consider that the script can run forever if necessary, kind of a fire and forget thing
you could create a second e.g. python script that would wait for a signal from the web server. With your server, after a user clicked a button, you could write to a file, that the python script periodically checks. Then, after writing "1" into the file, the script would do what you want, e.g. read sensor data every minute.
So you would run your web server and the python script alongside it. The script would be waiting for changes in the dedicated "signal" file. Then after the signal the script would do whatever you wanted.

How do I have a bash script continually run during business hours?

I have a Python program I run at all times of the day that alerts me when something I am looking for online is posted. I want to give this to my employees but I only want to have it email them during business hours.
I have a Ubuntu server and use a .sh. I have a command in crontab that runs on startup.
How do I make my command run from 9-5?
You could create a cronjob that starts the script every 5 minutes (or whatever often you want it to run) and additionally modify the script such that it creates a .lock file which it removes on exiting, but if it encounters it at the beginning it won't do anything (this way you don't have a long-running script active multiple times).

Categories

Resources