Last active
January 3, 2018 09:21
-
-
Save kuc-arc-f/908e82899ed47792fea4108fbaff16de to your computer and use it in GitHub Desktop.
GoogleHome (dialogFlow) webhook , tensorFlow reusult output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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