How to make app on your own?

How do you make your web app do simple calculations behind the scene and update variables without user input/interactions and client requests?

  • In my Python/Flask based web app, I am trying to calculate interest rates for a savings account. I have no problem performing such actions, but for the life of me, I do not know how to have the web app actually update the variables without any user actions. I want it to be performed in the background, like over time these variables (account balance and interest) gets changed, how should I go about doing such task? The way the web app is organized right now, is based on @app.route functions within the views .py , so each @app.route gets initiated when there is a request sent from the client, but I want the interests to be calculated and updated without any requests. Any help or guidance is appreciated. Thank you.

  • Answer:

    Note: I misunderstood the question. See comments for details. Make a function in Python/Flask that returns the current interest rate, and give it a route. @app.route('/api/current_rate/') def interest_rate(): return calc_rate() If you need to parse more information you can return a json dump of the data. On your website you now simply do ajax calls in the background. Have this within your document ready code: function update_rate() { $.ajax({ url: "/api/current_rate/", complete: function(data) { $("#rate_field).html(data); setTimeout(update_rate,5000); // 5000 = 5 seconds } }); } update_rate(); (I assume you are using jquery).

Julius Bier Kirkegaard at Quora Visit the source

Was this solution helpful to you?

Other answers

For background processing in python you could leverage form http://www.celeryproject.com. I have not used Flask, But did used lots of http://Djangoproject.com. There is something that comes with Django main project modules named https://docs.djangoproject.com/en/dev/topics/signals/%C3%A2%C2%80%C2%8E. Signals would be handful for similar tasks.

Mahdi Mazaheri

Hello, I'm not familiar with Flask but I think one way to do that is using scheduled tasks with crontab for example. You can do a small research on how to set up a cron job on your server with a python script to initiate the process. On the database level, you can also configure the jobs or event schedules that will run sql scripts to perform the same thing. On application level, I came across this Flask module, hope it can help also. https://pypi.python.org/pypi/Flask-Celery

Aimable Tuyishime

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.