I wrote a simple application that fetches stock quotes online, and post buy/sell orders. Now this is all done through the console. I read and followed a couple tutorials on Flask web apps. But I can't figure out how to run the server while fetching information to display on the Flask app at the same time.
The goal is to fetch the quotes for my watchlist, and display it on my index.html (localhost)
Here is what I tried to no avail:
Run my looping requests in one thread, and another thread to run the server. - Server wont start!
Run app.run() nested in main().
Please point me in the right direction to learn.
app = Flask(__name__)
@app.route('/')
def index(watchlist=None):
return render_template("index.html", watchlist=watchlist)
app.run()
################# main code has most of it's functions stripped out for legibility
def main():
qt = Questrade.Questrade()
qt.update_all()
watchlist = Watchlist.Watchlist(qt.quotes)
loop_count = 0
while 1:
print("loop start")
qt.update_all()
watchlist.update_stocks(qt.quotes)
loop_count += 1
print("loop end")
print(loop_count)
time.sleep(10)