Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Created October 15, 2021 15:32
Show Gist options
  • Save Utopiah/e0a598efbc747e390b5d08367bee63fd to your computer and use it in GitHub Desktop.
Save Utopiah/e0a598efbc747e390b5d08367bee63fd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# for https://twitter.com/utopiah/status/1449023602079240194
import http.server
import socketserver
import subprocess
PORT = 80
Handler = http.server.SimpleHTTPRequestHandler
class GetHandler(Handler):
def do_GET(self):
if self.path == "/photo/":
self.wfile.write("HTTP/1.1 200 OK\n\ntaking photo ... then go to <a href='/camera.jpg'>/camera.jpg</a> in a second".encode())
self.send_response(200)
subprocess.Popen(["raspistill", "-o", "camera.jpg"]).wait()
else:
Handler.do_GET(self)
with socketserver.TCPServer(("", PORT), GetHandler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment