sandbox webui as json responses

master
BuildTools 3 years ago
parent 1559c694e5
commit a90f9704e4
  1. 17
      plugins/dpt.py
  2. 20
      plugins/sandbox_web.py

@ -1,9 +1,12 @@
depends = ["bprint", "meido"] depends = ["bprint", "meido"]
from time import sleep
def run(l): def run(l):
pages = l['meido'].instance.get_catalog("g") while True:
for page in pages: pages = l['meido'].instance.get_catalog("g")
for thread in page["threads"]: for page in pages:
if not thread.get("sub"): continue for thread in page["threads"]:
if "/dpt/" in thread["sub"]: if not thread.get("sub"): continue
l["sand"].box["dpt"] = thread["no"] if "/dpt/" in thread["sub"]:
l["bprint"].p(f"found /dpt/! thread no: {thread['no']}") l["sand"].box["dpt"] = thread["no"]
l["bprint"].p(f"found /dpt/! thread no: {thread['no']}")
sleep(60)

@ -1,18 +1,26 @@
depends = ["bprint", "sand"] depends = ["bprint", "sand"]
from http.server import BaseHTTPRequestHandler, HTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs
import json
def run(l): def run(l):
class MyServer(BaseHTTPRequestHandler): class MyServer(BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):
self.send_response(200) self.send_response(200)
self.send_header("Content-type", "text/html") self.send_header("Content-type", "application/json")
self.end_headers() self.end_headers()
self.wfile.write(bytes("<html><head><title>komand'r</title></head>", "utf-8"))
self.wfile.write(bytes("<body><ul>", "utf-8")) queries = parse_qs(urlparse(self.path).query)
for key in l["sand"].box.keys():
self.wfile.write(bytes(f"<li>{key}:{l['sand'].box[key]}</li>", "utf-8")) single = None
self.wfile.write(bytes("</ul></body></html>", "utf-8")) for asked in queries.keys():
if l["sand"].box.get(asked):
single = asked
break
self.wfile.write(bytes(json.dumps(l["sand"].box[single]) if single else json.dumps(l['sand'].box, indent = 4), "utf-8"))
server = HTTPServer(("localhost", 8080), MyServer) server = HTTPServer(("localhost", 8080), MyServer)
l["bprint"].p("started sandbox server at port 8080") l["bprint"].p("started sandbox server at port 8080")
server.serve_forever()#TODO: SUPPRESS THE LOGGING FROM THE WEBSERVER (AND ONLY THE WEBSERVER) server.serve_forever()#TODO: SUPPRESS THE LOGGING FROM THE WEBSERVER (AND ONLY THE WEBSERVER)

Loading…
Cancel
Save