Commit a3ae4c16 authored by augustin_s's avatar augustin_s 🐍
Browse files

first try

parent 134662d8
#!/usr/bin/env python
print("running example 1")
#!/usr/bin/env python
print("running example 2")
#!/usr/bin/env python3
from glob import glob
import http.server
import socketserver
HOST = "localhost"
PORT = 9090
class ScriptServer(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
scr = self.path.strip("/")
if not scr.endswith(".py"):
scr += ".py"
scripts = sorted(glob("*.py"))
if scr not in scripts:
printable_scripts = "\n".join(scripts)
self.send_result(f"{scr} does not exist. choose from:\n", printable_scripts)
return
with open(scr) as f:
exec(f.read())
self.send_result(scr)
def send_result(self, *msg):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
msg = " ".join(msg)
msg = msg.split("\n")
msg = "<br>".join(msg)
msg = msg.encode()
self.wfile.write(msg)
print(msg)
if __name__ == "__main__":
socketserver.TCPServer.allow_reuse_address = True
with socketserver.ThreadingTCPServer((HOST, PORT), ScriptServer) as httpd:
print(f"serving at {HOST}:{PORT}")
httpd.serve_forever()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment