forked from bertrand-caron/andra_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (29 loc) · 977 Bytes
/
app.py
File metadata and controls
33 lines (29 loc) · 977 Bytes
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
from flask import Flask, request, make_response
from robot import say_with_emotion
from json import loads
from sys import stderr
import threading
app = Flask(__name__)
def async_say_with_emotion(*args):
stderr.write('Started thread')
thr = threading.Thread(target=say_with_emotion, args=args, kwargs={})
stderr.write('Started thread')
thr.start()
return 'DONE'
def async_say_with_emotion_2(*args):
pass
@app.route("/say")
def say():
try:
message, emotion = request.args['message'], request.args['emotion']
return_msg = async_say_with_emotion(message, emotion)
stderr.write(message)
return return_msg
except:
try:
message, emotion = request.form['message'], request.form['emotion']
return_msg = async_say_with_emotion(message, emotion)
stderr.write(message)
return return_msg
except Exception, e:
return 'Failure: {0}'.format(str(e))