Created
November 15, 2017 08:24
-
-
Save kuc-arc-f/efa71cbe6096f6fd3458f5cccd5bcf26 to your computer and use it in GitHub Desktop.
webhook (python27 ) GoogleHome +Iot( sensor data ) with dialogFlow
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 +"/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 ) | |
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