Created
February 6, 2013 22:47
-
-
Save danking/4726605 to your computer and use it in GitHub Desktop.
Change the volume!
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
| from http.server import HTTPServer, BaseHTTPRequestHandler | |
| from subprocess import check_output | |
| def respond(out, s): | |
| html_begin = "<html><head></head><body><pre>" | |
| html_end = "</pre></body></html>" | |
| response = html_begin + out.decode('utf-8') + html_end | |
| print(out) | |
| s.send_response(200) | |
| s.send_header("Content-type", "text/html") | |
| s.send_header("Content-length", len(response)) | |
| s.wfile.write(response.encode('utf-8')) | |
| class MyHandler(BaseHTTPRequestHandler): | |
| def do_GET(s): | |
| if 'up' in s.path: | |
| out = check_output(["amixer", "set", "Master", "2dB+"]) | |
| respond(out, s) | |
| elif 'down' in s.path: | |
| out = check_output(["amixer", "set", "Master", "2dB-"]) | |
| respond(out, s) | |
| else: | |
| s.send_response(404) | |
| s.end_headers() | |
| def run(server_class=HTTPServer, handler_class=MyHandler): | |
| server_address = ('', 1111) | |
| httpd = server_class(server_address, handler_class) | |
| httpd.serve_forever() | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment