forked from vicky002/slack-TheL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
53 lines (38 loc) · 1.19 KB
/
app.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
42
43
44
45
46
47
48
49
50
51
52
53
__author__ = 'vikesh'
import os
import wolframalpha
from flask import Flask, request, Response, redirect
try:
import config
wol_id = config.wolframalpha['app_id']
except:
wol_id = os.environ.get('APP_ID')
if not wol_id:
import sys
print 'No config.py found exisiting...'
sys.exit(0)
app = Flask(__name__)
client = wolframalpha.Client(wol_id)
@app.route('/thel',methods=['post'])
def thel():
'''
:Example:
/thel current weather in mumbai?
'''
text = request.values.get('text')
try:
res = client.query(text)
except UnicodeEncodeError:
return Response(('Sorry I did\'t get you. Would you please simplify your query?'
'%s is not valid input.' % text),
content_type='text\plain; charset=utf-8')
resp_qs = ['Hi Top Answer for "%s"\n' % text]
resp_qs.extend(next(res.results).text)
return Response(''.join(resp_qs),
content_type='text/plain; chatset=utf-8')
@app.route('/')
def hello():
return redirect('https://github.com/vicky002/slack-TheL')
if __name__ == '__main__':
port = int(os.environ.get('PORT',5000))
app.run(host='0.0.0.0', port=port)