Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created October 25, 2017 04:07
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/6ef74e14e1d477a025d5de55e4bae2e6 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/6ef74e14e1d477a025d5de55e4bae2e6 to your computer and use it in GitHub Desktop.
GoogleHome- Dialogflow (webhook) ,read Sensor value API (python )
# -*- 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