Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2020 16:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import subprocess
from flask import Flask, request
app = Flask(__name__)
PAGE = '''
<form action="/" method="post">
<input type="hidden" name="command" value="play">
<button type="submit" name="submit_param" value="submit_value">Play</button>
<form action="/" method="post">
<input type="hidden" name="command" value="stop">
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
command = request.values.get('command')
if command == 'play':["/bin/bash", "/home/pi/", "start"])
return PAGE
elif command == 'stop':["/bin/bash", "/home/pi/", "stop"])
return PAGE
if request.method == 'GET':
return PAGE
def play():
"""calls play command."""["/bin/bash", "/home/pi/", "start"])
return PAGE
def stop():["/bin/bash", "/home/pi/", "stop"])
return PAGE
def attempt_play():
"""checks status and only hits play if HDMI devices are off."""
status = subprocess.check_output(['/home/pi/', 'status'])
if status == b'off':["/bin/bash", "/home/pi/", "start"])
return PAGE
return 'other device active'
def status():
status = subprocess.check_output(['/home/pi/', 'status'])
if status == b'off':
return 'off'
elif status == b'on':
return 'on'
return 'unknown'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment