<commit_before>'use strict';

const express = require('express');
const bodyParser = require('body-parser');


var mqtt = require('mqtt')
var fs = require('fs');

var client = mqtt.connect('mqtt://broker.hivemq.com', {username:'gs99100', password:'<PASSWORD>'});


client.subscribe('apiai/ireading')
client.subscribe('apiai/sreading')

client.on('message', function (topic, message) {
  // message is Buffer 
  if (topic == 'apiai/sreading') {
  var sensoread = message.toString()
  console.log(message.toString())
  fs.writeFile("test", sensoread, function(err) {
    if(err) {
        return console.log(err);
    }
//console.log("The file was saved!");
});
}
})

const restService = express();
restService.use(bodyParser.json());

restService.post('/hook', function (req, res) {

    console.log('hook request');

    try {
        var speech = 'empty speech';

        if (req.body) {
            var requestBody = req.body;

            if (requestBody.result) {
                speech = '';

                if (requestBody.result.fulfillment) {
                    speech += requestBody.result.fulfillment.speech;
                    speech += ' ';
                }

                if (requestBody.result.action) {
                    speech += 'action: ' + requestBody.result.action;
                }
            }
        }

        console.log('result: ', speech);
		client.publish('apiai/ireading', speech)
		//console.log("rest in peace")
		fs.readFile('test','utf8', function(err, contents) {
					console.log("The content of the file"+contents);
//});
		var sread = contents
        return res.json({
            speech: speech,
            displayText:sread,
            source: 'apiai-webhook-IOTecosystem'
        });
        });
    } catch (err) {
        console.error("Can't process request", err);

        return res.status(400).json({
            status: {
                code: 400,
                errorType: err.message
            }
        });
    }
});

restService.listen((process.env.PORT || 5000), function () {
    console.log("Server listening");
});<commit_msg>with IEEE website custom search.<commit_after>'use strict';

const express = require('express');
const bodyParser = require('body-parser');


const restService = express();
restService.use(bodyParser.json());

restService.post('/hook', function (req, res) {

    console.log('hook request');

    try {
        var speech = 'empty speech';
	var query = 'empty query';
        if (req.body) {
            var requestBody = req.body;

            if (requestBody.result) {
		query = requestBody.result.resolvedQuery;
	        query += ' ';
                speech = '';

                if (requestBody.result.fulfillment) {
                    speech += requestBody.result.fulfillment.speech;
                    speech += ' ';
                }

                if (requestBody.result.action) {
                    speech += 'action: ' + requestBody.result.action;
                }
            }
        }
	    var google = require('C:/Users/HE_MAN/node_modules/googleapis/lib/googleapis.js');
	    var customsearch = google.customsearch('v1');
	    const CX = '000451306854787167072:pahciazb7zi';
	    const API_KEY = '<KEY>';
	    const SEARCH = query;

	    customsearch.cse.list({ cx: CX, q: SEARCH, auth: API_KEY }, function (err, resp) {
	    if (err) {
  		  return console.log('An error occured', err);
		     }
 	    // Got the response from custom search
 	    console.log('Result: ' + resp.searchInformation.formattedTotalResults);
 	    if (resp.items && resp.items.length > 0) {
	       
	    console.log('You can visit on: ' + resp.items[0].title + ' ' + resp.items[0].link );
		    	    
	    }
		    
	    var sreed =	resp    
	    return res.json({
            speech: resp,
            displayText:resp,
            source: 'apiai-webhook-IOTecosystem'
	    });
	    });
	    
        
    } catch (err) {
        console.error("Can't process request", err);

        return res.status(400).json({
            status: {
                code: 400,
                errorType: err.message
            }
        });
    }
});

restService.listen((process.env.PORT || 5000), function () {
    console.log("Server listening");
});
{'fraction_non_alphanumeric': 0.14474304573314475, 'fraction_numerical': 0.012258368694012258, 'mean_word_length': 1.9964689265536724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '689336', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1219, 'n_words': 251}