Skip to content

Instantly share code, notes, and snippets.

@bkeating
Created April 30, 2014 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeating/135e74023784ee62e22f to your computer and use it in GitHub Desktop.
Save bkeating/135e74023784ee62e22f to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from flask import Flask, jsonify, render_template, request
app = Flask(__name__)
from subprocess import check_output
@app.route('/_add_numbers')
def add_numbers():
"""Add two numbers server side, ridiculous but well..."""
a = request.args.get('a', 0, type=int)
b = request.args.get('b', 0, type=int)
return jsonify(result=a + b)
@app.route('/itunes/<control>')
def itunes_control(control=None):
r = check_output(['itunes.sh','%s' % control])
return jsonify(result=r)
@app.route('/doorbell/')
def doorbell(control=None):
r = check_output(['say','someone is at the front desk'])
return jsonify(result="someone is here!")
@app.route('/df')
def disk_space():
r = check_output(['df','-h'])
return jsonify(result=r)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment