Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f kuc-arc-f/
Created Nov 15, 2017

What would you like to do?
webhook (python27 ) GoogleHome +Iot( sensor data ) with dialogFlow
# -*- coding: utf-8 -*-
# 日本語
from urllib2 import urlopen
import webapp2
import json
import os
import sys
import traceback
import com_func
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']
if (sAct == "sen3a_inte"):
sURL =mDnsName +"/api-device1"
result = json.load(urlopen(sURL))
text = "ok, リビングの温度は、" +str(result["temperature"])+ " 度です。"
if (sAct == "sen3b_inte"):
sURL =mDnsName +"/api-device4"
result = json.load(urlopen(sURL))
text = "ok, 玄関の温度は、" +str(result["temperature"])+ " 度です。"
if (sAct == "sen2_inte"):
text = clsFunc.get_message(mDnsName )
dict = {'speech' : text , 'displayText' :text }
sDict =json.dumps(dict)
self.response.headers['Content-Type'] = 'application/json'
self.response.write( sDict )
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
You can’t perform that action at this time.