<commit_before>var schedule = require('node-schedule');
var request = require('request');
var nodemailer = require('nodemailer');

var config = require('./config');

var trains = config.trains;

var _sendMsg = function(trainInfo, station, time, sendto) {

    var transportInfo = 'smtps://{username}:{password}@smtp.gmail.com';
    transportInfo = transportInfo.replace('{username}', encodeURIComponent(config.mail.username));
    transportInfo = transportInfo.replace('{password}', encodeURIComponent(config.mail.password));

    var transporter = nodemailer.createTransport(transportInfo);

    var msg = config.msg;
    msg = msg.replace('{station}', station);
    msg = msg.replace('{trainno}', trainInfo.trainno.trim());
    msg = msg.replace('{time}', time);

    var mailOptions = {
        from: 'Train Alerter <' + config.mail.username + '>',
        to: sendto.join(','),
        subject: msg,
        text: 'Plan accordingly.'
    };

    // send mail with defined transport object
    transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: ' + info.response);
    });

};


for (var i = 0, trainLen = trains.length; i < trainLen; i++) {
    var train = trains[i];

    train.cronjob = schedule.scheduleJob(train.schedule, (function() {

        var station = this.station.toUpperCase();
        var dataUrl = config.dataUrl.replace('{station}', station);
        var trainno = this.trainno;
        var threshold = this.threshold;
        var sendto = this.sendto;

        request(dataUrl, function(error, response, body) {
            if (!error && response.statusCode == 200) {
                try {
                    var data = JSON.parse(body).response.results[0].data;

                    for (var j = 0, dataLen = data.length; j < dataLen; j++) {
                        var info = data[j];
                        if (trainno === parseInt(info.trainno.trim(), 10)) {

                            var sNewTime = info.newtime24.trim();
                            var sOrigTime = info.scheduled24.trim();
                            if (sNewTime.length > 0) {
                                var origTime = new Date();
                                origTime.setHours(sOrigTime.substring(0, 2));
                                origTime.setMinutes(sOrigTime.substring(2));

                                var newTime = new Date();
                                newTime.setHours(sNewTime.substring(0, 2));
                                newTime.setMinutes(sNewTime.substring(2));

                                var diff = (newTime - origTime) / 60 / 1000;

                                if (diff > threshold) {
                                    _sendMsg(info, station, diff, sendto);

                                }
                            }

                        }
                    }

                } catch (e) {
                    console.log('Unable to parse JSON response.', e);<commit_msg>Added some console logging<commit_after>var schedule = require('node-schedule');
var request = require('request');
var nodemailer = require('nodemailer');

var config = require('./config');

var trains = config.trains;

var _sendMsg = function(trainInfo, station, time, sendto) {

    var transportInfo = 'smtps://{username}:{password}@smtp.gmail.com';
    transportInfo = transportInfo.replace('{username}', encodeURIComponent(config.mail.username));
    transportInfo = transportInfo.replace('{password}', encodeURIComponent(config.mail.password));

    var transporter = nodemailer.createTransport(transportInfo);

    var msg = config.msg;
    msg = msg.replace('{station}', station);
    msg = msg.replace('{trainno}', trainInfo.trainno.trim());
    msg = msg.replace('{time}', time);

    var mailOptions = {
        from: 'Train Alerter <' + config.mail.username + '>',
        to: sendto.join(','),
        subject: msg,
        text: 'Plan accordingly.'
    };

    // send mail with defined transport object
    transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: ' + info.response);
    });

};


for (var i = 0, trainLen = trains.length; i < trainLen; i++) {
    var train = trains[i];

    train.cronjob = schedule.scheduleJob(train.schedule, (function() {

        var station = this.station.toUpperCase();
        var dataUrl = config.dataUrl.replace('{station}', station);
        var trainno = this.trainno;
        var threshold = this.threshold;
        var sendto = this.sendto;

        request(dataUrl, function(error, response, body) {
            if (!error && response.statusCode == 200) {
                try {
                    var data = JSON.parse(body).response.results[0].data;

                    for (var j = 0, dataLen = data.length; j < dataLen; j++) {
                        var info = data[j];
                        if (trainno === parseInt(info.trainno.trim(), 10)) {
			    console.log('Checking schedule for train: ' + trainno);
                            var sNewTime = info.newtime24.trim();
                            var sOrigTime = info.scheduled24.trim();
                            if (sNewTime.length > 0) {
                                var origTime = new Date();
                                origTime.setHours(sOrigTime.substring(0, 2));
                                origTime.setMinutes(sOrigTime.substring(2));

                                var newTime = new Date();
                                newTime.setHours(sNewTime.substring(0, 2));
                                newTime.setMinutes(sNewTime.substring(2));

                                var diff = (newTime - origTime) / 60 / 1000;

                                if (diff > threshold) {
                                    _sendMsg(info, station, diff, sendto);

                                }
                            }

                        }
                    }

                } catch (e) {
                    console.log('Unable to parse JSON response.', e);
{'fraction_non_alphanumeric': 0.12506074842054107, 'fraction_numerical': 0.008099789405475458, 'mean_word_length': 1.6704152249134947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7494256', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1614, 'n_words': 361}