Created
October 15, 2021 15:32
-
-
Save Utopiah/e0a598efbc747e390b5d08367bee63fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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