-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
116 lines (99 loc) · 3.9 KB
/
deploy.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from flask import Flask
import urllib
import json
import os
import math
from flask import request
from flask import make_response
from dateutil.parser import parse
app=Flask(__name__)
@app.route('/webhook',methods=['POST'])
def webhook():
req=request.get_json(silent=True,force=True)
print("hi m in function webhook")
res=makeWebhookResult(req)
res=json.dumps(res,indent=4)
r=make_response(res)
r.headers['Content-Type']='application/json'
return r
from datetime import date
from datetime import time
from datetime import datetime
from datetime import timedelta
import datetime as dt
import json
str_end = "\n\nIs there anything else you would like to know?"
strEndHin="\n\nक्या कुछ और है जो आप जानना चाहेंगे?"
hinDay={"Sunday":"रविवार","Monday":"सोमवार","Tuesday":"मंगलवार","Wednesday":"बुधवार","Thursday":"गुरुवार","Friday":"शुक्रवार","Saturday":"शनिवार"}
def checkJsonMeal(weekno,today,lang):
if(lang=="hi"):
with open('dataIconicGirlsHin.json') as json_file:
data=json.load(json_file)
ls=data[str(weekno)][hinDay.get(today.strftime("%A"))]
s='\n'
for key in ls.keys():
s+="\n" + key + ":\n"
s+='\n'.join(ls[key])
return ("आपका भोजन," + str(today.date()) + ":" + s + strEndHin)
else:
with open('data_iconicGirls.json') as json_file:
data=json.load(json_file)
ls=data[str(weekno)][today.strftime("%A")]
s='\n'
for key in ls.keys():
s+="\n" + key + ":\n"
s+='\n'.join(ls[key])
return ("Your meal for " + str(today.date()) + " is " + s + str_end)
def checkJsonfood(weekno,today,foodType,lang):
if(lang=="hi"):
with open('dataIconicGirlsHin.json') as json_file:
data=json.load(json_file)
ls=data[str(weekno)][hinDay.get(today.strftime("%A"))][foodType]
s='\n'.join(ls)
return("आपका "+foodType+","+str(today.date()) +" : "+s+strEndHin)
else:
with open('data_iconicGirls.json') as json_file:
data=json.load(json_file)
ls=data[str(weekno)][today.strftime("%A")][foodType]
s='\n'.join(ls)
return("Your "+foodType+" for "+str(today.date()) +" is "+s+str_end)
def makeWebhookResult(req):
ref_date=dt.datetime(2019,3,11).date()
result=req.get("queryResult")
print(result)
parameters=result.get("parameters")
lang=result.get("languageCode") ####
if req.get("queryResult").get("action")=="intent.messMenu":
takeTime=parameters.get("date")
if(takeTime==""):
today=datetime.now()
else:
today =parse(takeTime)
weekno=(abs(math.floor(((today.date()-ref_date).days)/7)))%2
speech=checkJsonMeal(weekno,today,lang)
print("response from action messMenu")
print(speech)
return{
"fulfillmentText":speech,
"source":"ThaparMessbot"
}
if req.get("queryResult").get("action")=="intent.foodTime":
takeTime=parameters.get("date")
today =parse(takeTime)
if(takeTime==""):
today=datetime.now()
else:
today =parse(takeTime)
foodType=parameters.get("food")
weekno=(abs(math.floor(((today.date()-ref_date).days)/7)))%2
speech=checkJsonfood(weekno,today,foodType,lang)
print("response from action foodtime")
print(speech)
return{
"fulfillmentText":speech,
"source":"ThaparMessbot"
}
if __name__ =='__main__':
port=int(os.getenv('PORT',80))
print("Starting app on port %d" %(port))
app.run(debug=True,port=port,host='0.0.0.0')