Create a gist now

Instantly share code, notes, and snippets.

Embed
GoogleHome (dialogFlow) webhook , tensorFlow reusult output
# -*- coding: utf-8 -*-
# 日本語
from urllib2 import urlopen
import webapp2
import json
import os
import sys
import traceback
import com_func
#define
mDnsName="http://your-dns.com"
#
class WebhookHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write("this is [GET] url" )
def post(self):
clsFunc= com_func.funcClass()
json_data = self.request.body
obj = json.loads(json_data)
sAct = obj['result']['action']
text=""
if (sAct == "sen3a_inte"):
sURL =mDnsName +"/device1-api"
result = json.load(urlopen(sURL))
res2 = clsFunc.get_yosokuParam( mDnsName ,'abc', 1)
text = "ok, リビングの温度は、" +str(result["temperature"])+ " 度です。"
text += "人口知能で予測します。"
text += "1時間後の温度は、"+ str(res2["yNum"]) +"度です。"
text += str(res2["ritu"])+ "%"
sHantei =clsFunc.get_hantei(float(res2["ritu"] ) )
text +=sHantei
text += ", 6時間後の温度は、"+ str(res2["yNum6"]) +"度です。"
text += str(res2["ritu6"])+ "%"
sHantei6 =clsFunc.get_hantei(float(res2["ritu6"] ) )
text +=sHantei6
if (sAct == "sen3b_inte"):
sURL =mDnsName +"/device4-api"
result = json.load(urlopen(sURL))
text = "ok, 玄関の温度は、" +str(result["temperature"])+ " 度です。"
if (sAct == "sen2_inte"):
text = clsFunc.get_message(mDnsName )
try:
dict = {'speech' : text , 'displayText' :text }
sDict =json.dumps(dict)
self.response.headers['Content-Type'] = 'application/json'
self.response.write( sDict )
except:
print "--------------------------------------------"
print traceback.format_exc(sys.exc_info()[2])
print "--------------------------------------------"
app = webapp2.WSGIApplication([
('/webhook', WebhookHandler )
], debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment