-
Notifications
You must be signed in to change notification settings - Fork 2
/
support.py
69 lines (48 loc) · 1.8 KB
/
support.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
from process import do_what_i_say
import process
from flask import Flask, request, make_response, jsonify,Response
from multiprocessing import Process
app = Flask(__name__)
log = app.logger
@app.route('/page', methods=['GET','POST'])
def webhook():
req = request.get_json(silent=True, force=True)
print(req)
try:
action = req.get('queryResult').get('action')
except AttributeError:
return 'json error'
inp = []
if action == 'platform':
# print(req['queryResult']['parameters'])
if len(req['queryResult']['parameters']) == 0:
inp.append(['Codeforces','Codechef','Hackerearth'])
else:
inp.append(req['queryResult']['parameters'])
inp.append("search")
elif action == 'reminder': # make necessary arrangements for index of reminder,also configure in diagflow
inp.append(None)
inp.append("reminder")
# print(inp)
output = do_what_i_say(inp)
# print(output)
res = {
"fulfillmentText": "fulfillmentText",
"fulfillmentMessages":[],
"source":"contests from webhook"
}
for contest in output:
displayText = contest['name'] + " From: "+str(contest['startTime']) + " To: "+str(contest['endTime']) + " on "+contest['platform']+ ". Go to: "+contest['link']
temp = {'simpleResponses':{'simpleResponses':[{"speech": "Text response",'displayText':displayText}]}}
res['fulfillmentMessages'].append(temp)
# Display this text in zulip and messenger
output = json.dumps(res,indent=4)
resp = Response(output)
resp.headers['Content-Type'] = 'application/json'
return resp
if __name__ == '__main__':
p1 = Process(target=process.ini)
p1.start()
app.run(debug=True, host='0.0.0.0')
p1.join()