-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (46 loc) · 1.43 KB
/
app.py
File metadata and controls
54 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# API app for controlling AV devices
from flask import Flask, make_response, jsonify, request
#import user
import json
import directv
dtv = directv.DirecTV("192.168.88.253")
app = Flask(__name__)
def check_key(key):
if key=='SOMESORTOFFNORDKEYHASH':
return True
else:
return False
@app.route('/', methods=['GET'])
def index():
key_check = check_key(request.args.get('key'))
if key_check:
return jsonify(name='Petraberg AV System',location='Minneapolis, MN')
#return "Valid Key" + request
else:
return jsonify(error='Invalid Key')
#return "Invalid Key"
@app.route('/dtv/key/<key>', methods=['GET'])
def dtv_key(key):
key_check = check_key(request.args.get('key'))
if key_check:
dtv.sendkey(key,'keyPress')
return jsonify(keyPress=key)
else:
return jsonify(error='Invalid Key')
@app.route('/dtv/chan/<chan>', methods=['GET'])
def dtv_chan(chan):
key_check = check_key(request.args.get('key'))
if key_check:
dtv.sendchan(chan,'0')
return jsonify(channel=chan)
else:
return jsonify(error='Invalid Key')
@app.errorhandler(404)
def not_found(error):
key_check = check_key(request.args.get('key'))
if key_check:
return make_response(jsonify(error='Not found'), 404)
else:
return jsonify(error='Invalid Key')
if __name__ == '__main__':
app.run(host='0.0.0.0')