I am creating a Python flag web application with JavaScript. I'm starting javascript.
Now I am performing the following process:
In Flask Python code,
1. I get data by abandoning the Internet (numeric data that is updated every minute). 2. use the data and calculate something and get the final numbers. 3. make a list containing the final numbers 4. Prepare the list on the page by adding the list to the Flask page definition 5. Now in HTML, get the list by capturing it with the {{data | safe}}
6. Use it with Javascript to create a chart.
The problem is this: In step 1, the data that I receive is updated every minute. For example, this web page now has 15 data points. I am parsing the last 10 data points from this web page and then putting them in a list in my Python and then following the next steps and making a chart on my web page. In a minute, 16 data points will be available on the data source web page, and I will need to get the last 10 data points. In this case, I need to run python code again in order to get the last 10 data points in order to use them to create a chart on my web page.
So, I need to always run all the python code, which is the init.py file for the entire Flask file, and redisplay my web page to see the updated diagram. If I did not restart the init.py file on my server, then even after 10 minutes or 2 hours I will see only the data that I checked for the first time forever.
How can I start Flask and always get updated data without restarting init.py every time.
I thought about using time.sleep (60) so that the python application file for flacks starts every 1 minute. But it really takes a long time when my code thinks a lot more to calculate. And really do not work.
How do I solve this problem?
Should I use time.sleep? or the best way?