-
Notifications
You must be signed in to change notification settings - Fork 0
/
lampeflaske.py
executable file
·41 lines (27 loc) · 1.1 KB
/
lampeflaske.py
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
#!/usr/bin/env python3
import pprint
import os
import lamper
from flask import Flask, request, jsonify
from flask_api import status
app = Flask(__name__)
@app.route("/", methods=['POST', 'GET'])
def hello():
pprint.pprint(request.form)
if request.form.get('command') != '/lamper':
return "wrong command" , status.HTTP_400_BAD_REQUEST
if request.form.get('team_id') != os.environ['SLACK_TEAMID']:
return "wrong team id" , status.HTTP_403_FORBIDDEN
if request.form.get('token') != os.environ['SLACK_TOKEN']:
return "wrong token", status.HTTP_403_FORBIDDEN
if request.form.get('channel_id') != os.environ['SLACK_CHANNELID']:
return "wrong channel id", status.HTTP_403_FORBIDDEN
if request.form.get('text') not in lamper.colors.keys():
return "wrong color" , status.HTTP_400_BAD_REQUEST
lamper.set_dmx(lamper.colors[request.form.get('text')])
#return "Hello World! " + request.form.get('text')
r = {
'response_type': 'in_channel',
'text': 'Light switched to {}'.format(request.form.get('text')),
}
return jsonify(r)