Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Last active January 3, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/908e82899ed47792fea4108fbaff16de to your computer and use it in GitHub Desktop.
Save kuc-arc-f/908e82899ed47792fea4108fbaff16de to your computer and use it in GitHub Desktop.
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