/dpt/ getter + sandbox frontend example

master
BuildTools 3 years ago
parent 1b98ad9155
commit 1559c694e5
  1. 9
      libs/meido.py
  2. 1
      libs/sand.py
  3. 8
      plugins/dpt.py
  4. 19
      plugins/sandbox_web.py

@ -5,12 +5,19 @@ class driver():
self.endpoint = endpoin self.endpoint = endpoin
self.image_endpoint = image self.image_endpoint = image
self.static_endpoint = static self.static_endpoint = static
self.sess = requests.Session()
def get_boards(self): def get_boards(self):
return self.wrap_route("/boards.json") return self.wrap_route("/boards.json")
def get_threads(self, board): def get_threads(self, board):
return self.wrap_route(f"/{board}/threads.json") return self.wrap_route(f"/{board}/threads.json")
def get_catalog(self, board): def get_catalog(self, board):
return self.wrap_route(f"/{board}/catalog.json") return self.wrap_route(f"/{board}/catalog.json")
def get_archive(self, board):
return self.wrap_route(f"/{board}/archive.json")
def get_page(self, board, page):
return self.wrap_route(f"/{board}/{page}.json")
def get_thread(self, board, thread_id):
return self.wrap_route(f"/{board}/thread/{thread_id}.json")
def wrap_route(self, route): def wrap_route(self, route):
return json.loads(requests.get(self.endpoint+route).text) return json.loads(self.sess.get(self.endpoint+route).text)
instance = driver("https://a.4cdn.org", "https://i.4cdn.org", "https://s.4cdn.org") instance = driver("https://a.4cdn.org", "https://i.4cdn.org", "https://s.4cdn.org")

@ -0,0 +1 @@
box = {}

@ -1,3 +1,9 @@
depends = ["bprint", "meido"] depends = ["bprint", "meido"]
def run(l): def run(l):
l["bprint"].p(f"found {len(l['meido'].instance.get_boards())} boards") 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']}")

@ -0,0 +1,19 @@
depends = ["bprint", "sand"]
from http.server import BaseHTTPRequestHandler, HTTPServer
def run(l):
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>komand'r</title></head>", "utf-8"))
self.wfile.write(bytes("<body><ul>", "utf-8"))
for key in l["sand"].box.keys():
self.wfile.write(bytes(f"<li>{key}:{l['sand'].box[key]}</li>", "utf-8"))
self.wfile.write(bytes("</ul></body></html>", "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)
server.server_close()
Loading…
Cancel
Save