#!/usr/bin/env python3 """Simple web server: one button to turn off all kids' devices.""" import json from http.server import HTTPServer, BaseHTTPRequestHandler from devices import shutdown_all class Handler(BaseHTTPRequestHandler): def do_GET(self): if self.path == "/" or self.path == "/index.html": self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() self.wfile.write(HTML.encode()) else: self.send_error(404) def do_POST(self): if self.path == "/run": try: actions = shutdown_all() status = "ok" except Exception as e: actions = [{"icon": "❌", "title": "Error", "detail": str(e)}] status = "error" self.send_response(200) self.send_header("Content-Type", "application/json") self.end_headers() self.wfile.write(json.dumps({"status": status, "actions": actions}).encode()) else: self.send_error(404) def log_message(self, format, *args): pass HTML = """\
TV + Gabi's computer + Gaja's computer