morgan samage
New Coder
Hope the following makes sense. It is something that I have never had to do this before, so I am basically looking for ideas/best practices.
I have a hosted website (currently Wordpress, but I could change this to flask?) that contains a directory, that contains a json file, e.g.
https://my_domain.com/my_folder/my_file.json
From a python app running locally, I want to download the json file, but before the file is downloaded, I want to run a server side python script that will extract the latest information from a mysql database to update the json file. I then want to return the json file to the client side python app.
As mentioned, I have never needed to do this before so I am not sure of the correct/best way to do it, or if wordpress will even interface with python in this way. Solutions that I have thought of so far, include: -
1) Interface directly with the hosted database from the client side python app.
I could connect to the hosted database from the client side python app to access the information that I want, but I don't really like this idea.
2) Add a trigger to the hosted database
I thought about adding a trigger to the hosted database so that each time new data is written, the json file is updated. However, the only way I can see this working would be to call a python script from the trigger that would update the json file. I did read somewhere that the database would need an extension for this to work, and I don't think that will be an option from the hosting company?
3) Periodically run a server side python script
I could periodically run a python script on the hosted site using a cron job to update the json file, but this will be akin to polling and is not the right solution.
So, I hope someone has some better ideas on this than me, and that this is the correct forum for this type of question?
I have a hosted website (currently Wordpress, but I could change this to flask?) that contains a directory, that contains a json file, e.g.
https://my_domain.com/my_folder/my_file.json
From a python app running locally, I want to download the json file, but before the file is downloaded, I want to run a server side python script that will extract the latest information from a mysql database to update the json file. I then want to return the json file to the client side python app.
As mentioned, I have never needed to do this before so I am not sure of the correct/best way to do it, or if wordpress will even interface with python in this way. Solutions that I have thought of so far, include: -
1) Interface directly with the hosted database from the client side python app.
I could connect to the hosted database from the client side python app to access the information that I want, but I don't really like this idea.
2) Add a trigger to the hosted database
I thought about adding a trigger to the hosted database so that each time new data is written, the json file is updated. However, the only way I can see this working would be to call a python script from the trigger that would update the json file. I did read somewhere that the database would need an extension for this to work, and I don't think that will be an option from the hosting company?
3) Periodically run a server side python script
I could periodically run a python script on the hosted site using a cron job to update the json file, but this will be akin to polling and is not the right solution.
So, I hope someone has some better ideas on this than me, and that this is the correct forum for this type of question?