I created a script with python that extracts a KPI from a database and compares it with another KPI, then I created a push notification that sent me a message on the desktop if the KPI of the database is out of its tolerance. My question is how can I automate this push notifier in my desktop? I mean every time the KPI changes I want to receive automatically a message from the notifier on the Desktop? Do you have any idea, please? Thank you :)
If you want to do that locally. I can think of 2 options.
You need to create another function/script that detects if there is a change in the database. Then
You have that script running in the background constantly. You can make it check for changes every minute or so. If there is a change, then it calls the script that you made. You can also make it being executed every time you turn on your PC
Similar to before but with the use of a windows scheduler. That schedules can run the script every minute or so.
Related
I got a big script that retrieves a lot of data via an API (Magento Invoices). This script is launched by a cron every 20 minutes. But sometimes, we need to refresh manually for getting the last invoiced orders. I have a dedicated page for this.
I would like to prevent from manual launching of the script by testing if it's already running because both API and script take a lot of ressources and time.
I tried to add a "process" model with is_active = True/False that would be tested and avoid re-launching if script is already active. At the start of the script, I switch the process status to TRUE and set it to FALSE when the script has finished.
But it seems that the 2nd instance of the script waits for the first to be finished before starting. At the end, both scripts are run because process.is_active always = False
I also tried with request.session variable, but same issue.
Spent lotsa time on this but didn't find a way to achieve my goal.
Has anyone already faced such a case ?
I'm woriking on a project that checks if LEDSTATUS from a database has the value "0" then led is off, if the value is "1" led is on.
I searched and found out that there is something called UDF that can run scripts but am not sure if it is possible if the database is not local (on a server).
is it possible? if yes how?
I created two python scripts one that turn led on and the other one to turns it off.
I will create a database with one table LEDSTATUS and will create a trigger that will run when ever the value of LEDSTATUS gets changed, if the value is 0 then run python script that turn led off, and if the value is 1 run the other script.
If you don't have access to the remote database server, then probably not.
You could run a cronjob (or any scheduled task) that periodically checks the database and runs the appropriate script, but there will be a delay between when the database changes and your script runs depending on how often it runs.
EDIT (4/2/2019)
I don't think a trigger is the right solution. Triggers are meant to run queries internally when some action is performed, not fire off external scripts. There may be ways to accomplish this, but I'm not familiar with any so I can't give any advice on that.
I would recommend one of two options:
Write a python script that periodically checks your database (this is called polling) for the LED status and interacts with the raspberry pi to update the LED.
Put your database behind an API which can update both the database and the LED, and change whatever is updating the LED status database directly to instead interact with the API. Flask is a great python web framework you could use, and the requests package can be used to interact with it.
I would recommend option 1, but option 2 would be simpler to implement. Both solutions could be run from your raspberry pi.
Database triggers are for DELETE, INSERT, UPDATE sql queries. You cannot trigger a python script with it.
At some point you set the database field to 0 or to 1 with an UPDATE SQL query.
The event based approach is to run the according python script before or after you performed the sql update query. Python could run as a webserver on the pi and you can send values via GET or POST.
The polling approach is to query the database every x (mili)second with a python script or similar and execute turn on/off functions accordingly.
I wrote a little python Script that fetches data from some website using hard coded credentials ( i know its bad but not part of this question).
The website has new data every day and im gathering data from a whole week and parse it into a single .pdf.
I've already adjusted the script to always generate a pdf off last week by default. (no params needed)
Im kinda lazy and don't want to run the script every week by hand.
So is it possible to run the script at certain times, for example every monday at 10am?
Sure, just utilize Windows' task scheduler. There you can create new tasks to your delight and let it run commands to whatever times or intervalls you want. The task schedulers' GUI should be self-explanatory, but to be concrete on your example:
Configure the run time (weekly, monday, 10am) under triggers
Add a new action and give it your Python interpreter as the command and your script to be run as the argument
Configure the rest according to your needs
I am trying to build a node app which calls python script (takes a lot of time to run).User essentially chooses parameters and then clicks run which triggers event in socket.on('python-event') and this runs python script.I am using sockets.io to send real-time data to the user about the status of the python program using stdout stream I get from python.But the problem I am facing is that if the user clicks run button twice, the event-handdler is triggered twice and runs 2 instances of python script which corrupts stdout.How can I ensure only one event-trigger happens at a time and if new event trigger happens it should kill previous instance and also stdout stream and then run new instance of python script using updated parameters.I tried using socket.once() but it only allows the event to trigger once per connection.
I will use a job queue to do such kind of job, store each job's info in a queue, so you can cancel it and get its status. You can use a node module like kue.
To work a bit on my Python, I decided to try to code a simple script for my private use which monitors sites with offers and sends you an email whenever a new offer which you are interested in pops out. I guess I could handle the coding part (extracting the newest one from HTML and such) but I've never really run online any script which requires being fired every N minutes or so. What kind of hosting/server do I need to make my script run independently of my computer and refresh every, say, 5 minutes sending me an email when there's an update?
If you have shell access, you an use crontab to schedule a recurring job.
Otherwise you can use a service like SetCronJob or EasyCron or similar to invoke a script regularly.
Some hosters also provide similar functionalities in their administration interface...