Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created October 19, 2014 02:22
Show Gist options
  • Save dtinth/2baf672b24fc115a47b8 to your computer and use it in GitHub Desktop.
Save dtinth/2baf672b24fc115a47b8 to your computer and use it in GitHub Desktop.
Some simple HTTP server to run command-line apps
#!/usr/bin/python
# Based on http://www.acmesystems.it/python_httpserver
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import os
class MyRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/play':
self.play()
elif self.path == '/stop':
self.stop()
else:
self.not_found()
def play(self):
os.system("osascript -e 'tell application \"iTunes\" to play'")
self.ok()
def stop(self):
os.system("osascript -e 'tell application \"iTunes\" to stop'")
self.ok()
def ok(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write("Cool")
def not_found(self):
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write("Not Found")
server = HTTPServer(('127.0.0.1', 1234), MyRequestHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment