0

I have some code which outputs information as it is acquired. Like this:

while not search_complete:
    bulk_results = session.get(urljoin(secrets['baseurl'],bulk_string), headers={'Content-Type':'application/json', 'PAPI-Use-Prefixes':'false' }, proxies=proxies)
    pprint(bulk_results.json())
    if bulk_results.json()['searchTargetStatus'] == 'COMPLETE':
         search_complete = True
pprint(bulk_results.json())

So, the 4th line will print over and over as 'searchTargetStatus' remains "PENDING", then once it is "COMPLETE" line 7 prints a final output.

I need the PENDING prints and the final output to be able to be seen on a website page hosted using Gunicorn and Flask (also uses Flash for some popup messages). The preference would be for continuous output into some kind of frame view field until the code is finished. Whatever Python would print to my IDE would be fine to see on the page. Like an AWS deployment shows logs as different pieces of the deployment occurs, until done.

However, I would be fine with an all at once output, as long as it reaches the web page and shows the same info that I can see in my CLI (or IDE) from the Python print command output.

DjIns1ght
  • 13
  • 4
  • You will need to use some javascript to show a live update. – Alex Hall Mar 25 '20 at 17:11
  • You are looking for that (How to implement server push in Flask framework?)[https://stackoverflow.com/questions/12232304/how-to-implement-server-push-in-flask-framework] – Victor Mar 25 '20 at 18:45
  • @AlexHall - Can you give any examples? Someone else locally suggested using Vue.js to output Python to the webpage, but I think it has to go through Flask itself. – DjIns1ght Mar 25 '20 at 19:17
  • @Victor Ok. This is interesting. It seems "Server-Side Events" is the key. One of the replies created Flask-SSE https://github.com/singingwolfboy/flask-sse as a tool to assist in this usage. Any thoughts on that tool? Thanks! – DjIns1ght Mar 25 '20 at 19:20
  • I've never used it, it's an implementation with redis Pub/Sub, so you may have to take a look at how this works. If you have time to spend, you can do it yourself and learn how yield works and how to generate a Server Side Event, that's quite interesting too! – Victor Mar 25 '20 at 20:10
  • And for sure for Flask-SSE you need a redis instance running. – Victor Mar 25 '20 at 20:33

0 Answers0