I have loaded the modules using npm, and I have the following code snippet
var request = require('request');
var cheerio = require('cheerio');
var url = "https://www.google.com/search?q=current+date";
request(url, function(error, response, body) {
if(!error) {
console.log("Status code: " + response.statusCode);
var $ = cheerio.load(body);
date = $("div > div > div > div > span").text().trim();
console.log("Date: " + date);
} else {
console.log("Error: " + error);
}
});
I want to call a function that does the same thing from amazon's alexa, I tried:
'GetDate': function(){
//this.emit(':tell', 'activated');
var url = "https://www.google.com/search?q=current+date";
request(url, function(error, response, body) {
if(!error) {
//var $ = cheerio.load(body);
//var date = $("div > div > div > div > span").text().trim();
//this.emit(':tell', 'Date: ' + date);
this.emit(':tell', 'activated1');
} else {
//this.emit(':tell', 'Error connecting');
this.emit(':tell', 'activated2');
}
});
},
But it's producing an error and I cannot tell why. Any ideas?
via Noah L
No comments:
Post a Comment