import subprocess from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import SocketServer import subprocess, os, time def onStart(): print "onStart" os.environ["DISPLAY"] = ":0" subprocess.call(["sudo","/opt/vc/bin/tvservice","-p"]) time.sleep( 1 ) subprocess.call(["xset","dpms","force","on"]) subprocess.call(["xset","s","off"]) subprocess.call(["xset","-dpms"]) subprocess.call(["xset","s","noblank"]) subprocess.Popen(["epiphany-browser","-a","--profile","/home/pi/.config","http://1060research.com"]) time.sleep( 10 ) subprocess.call(["wmctrl","-r","1060 Research","-b","add,fullscreen"]) def onEnd(): print "onEnd" os.environ["DISPLAY"] = ":0" subprocess.call(["killall","epiphany-browser"]) subprocess.call(["sudo","/opt/vc/bin/tvservice","-o"]) class S(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() def do_GET(self): if self.path=="/start": onStart() if self.path=="/end": onEnd() self.send_response(200) self.send_header('Content-type',"text/plain") self.end_headers() self.wfile.write("hello") return def do_HEAD(self): self._set_headers() def do_POST(self): # Doesn't do anything with posted data self._set_headers() self.wfile.write("

POST!

") def run(server_class=HTTPServer, handler_class=S, port=8082): server_address = ('', port) httpd = server_class(server_address, handler_class) print 'Starting httpd...' httpd.serve_forever() if __name__ == "__main__": from sys import argv if len(argv) == 2: run(port=int(argv[1])) else: run()