From a90f9704e4c0183f09a63415353dc00d098a96d7 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 11 Jun 2022 23:24:56 -0400 Subject: [PATCH] sandbox webui as json responses --- plugins/dpt.py | 17 ++++++++++------- plugins/sandbox_web.py | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/plugins/dpt.py b/plugins/dpt.py index ac1f02e..15b8c1b 100644 --- a/plugins/dpt.py +++ b/plugins/dpt.py @@ -1,9 +1,12 @@ depends = ["bprint", "meido"] +from time import sleep def run(l): - pages = l['meido'].instance.get_catalog("g") - for page in pages: - for thread in page["threads"]: - if not thread.get("sub"): continue - if "/dpt/" in thread["sub"]: - l["sand"].box["dpt"] = thread["no"] - l["bprint"].p(f"found /dpt/! thread no: {thread['no']}") + while True: + pages = l['meido'].instance.get_catalog("g") + for page in pages: + for thread in page["threads"]: + if not thread.get("sub"): continue + if "/dpt/" in thread["sub"]: + l["sand"].box["dpt"] = thread["no"] + l["bprint"].p(f"found /dpt/! thread no: {thread['no']}") + sleep(60) diff --git a/plugins/sandbox_web.py b/plugins/sandbox_web.py index a49df85..3ab3663 100644 --- a/plugins/sandbox_web.py +++ b/plugins/sandbox_web.py @@ -1,18 +1,26 @@ depends = ["bprint", "sand"] from http.server import BaseHTTPRequestHandler, HTTPServer +from urllib.parse import urlparse, parse_qs +import json def run(l): class MyServer(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) - self.send_header("Content-type", "text/html") + self.send_header("Content-type", "application/json") self.end_headers() - self.wfile.write(bytes("komand'r", "utf-8")) - self.wfile.write(bytes("", "utf-8")) + + queries = parse_qs(urlparse(self.path).query) + + single = None + 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) l["bprint"].p("started sandbox server at port 8080") server.serve_forever()#TODO: SUPPRESS THE LOGGING FROM THE WEBSERVER (AND ONLY THE WEBSERVER)