This is my first question, so I hope it will be done correctly;)
Some "home made" python scripts have been tasked to give them a web interface. This script is used to see some web sites / applications availability through curl commands. One very important aspect of this script is that it gives its results in real time, the line writing by line for standard output.
By giving the web interface to this script, the main goal is that the script can be used easily from anywhere through a smartphone, for example, the web interface should be quite basic, and "plug -in-free ".
My problem is that most solutions were thought or found on the web (AJAX, Django, even a simple post), losing this important "real-time" aspect, the page before sending the browser A whole generation is required.
Any ideas on how to do this properly?
Thanks in advance.
A sketch for solution:
Create an HTML file that contains the script's output For a dedicated DIV, layout for your web page:
& lt; Html & gt; & Lt; Body & gt; & Lt; Div id = "scriptoutput" & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" src = "localhost: 8000 / runscript" /> & Lt; / Body & gt; & Lt; / Html & gt; This HTML file can be served using whatever you want.
Now, write a simple HTTP server that runs scripts and converts each line into JavaScript commands (eg Python):
Import OS F = os. Popen ('ping 127.0.0.1') for category (30): ln = f.readline () print "document.getElementById ('script output'). InnerHTML + '' pre & gt;% s & lt ; / Pre>
"% ln You can use any CGI / WSGI server for work, or if performance is important If not Also use Python's own BaseHTTPServer class.
This trick does because most browsers execute and execute javascript scripts because they are received (and not only when the request is completed) - Note that any voting or server-side Storage is not required!
Comments
Post a Comment