Created
October 25, 2017 04:07
-
-
Save kuc-arc-f/6ef74e14e1d477a025d5de55e4bae2e6 to your computer and use it in GitHub Desktop.
GoogleHome- Dialogflow (webhook) ,read Sensor value API (python )
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 | |
#define | |
mDnsName="http://your-DNS.jp" | |
# | |
class WebhookHandler(webapp2.RequestHandler): | |
def get(self): | |
self.response.headers['Content-Type'] = 'text/plain' | |
self.response.write("this is [GET] url" ) | |
def post(self): | |
sURL =mDnsName +"/tst/ghome/dat/device1-api" | |
result = json.load(urlopen(sURL)) | |
# text = "ok, temperature is " +str(result["temperature"])+ " degree" | |
text = "ok, リビングの温度は、" +str(result["temperature"])+ " 度です。" | |
sDat = "{'speech':'"+ text+ "'" | |
sDat += ",'displayText' :'"+ text+ "'" | |
sDat += "}" | |
sJs = json.dumps(sDat ) | |
dict = {'speech' : text , 'displayText' :text } | |
sDict =json.dumps(dict) | |
#print(json.dumps(dict) ) | |
# print(sJs ) | |
self.response.headers['Content-Type'] = 'application/json' | |
self.response.write( sDict ) | |
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