<commit_before>var rest = require('restler');
var jf = require('jsonfile');

var neaCredentialsPath = './private/nea_credentials.json';
var neaAuthKey = jf.readFileSync(neaCredentialsPath).key;

var nowcastURL = 'http://www.nea.gov.sg/api/WebAPI?dataset=nowcast&keyref=' +
    neaAuthKey;
var nowcastJSON;
var clementiNowcast;

var psiURL = 'http://www.nea.gov.sg/api/WebAPI/?dataset=psi_update&keyref=' +
    neaAuthKey;
var psiJSON;
var westPSI3;
var westPSI24;

rest.get(nowcastURL).on('complete', function(data) {
    nowCastJSON = data.channel.item[0];
    clementiNowcast = nowCastJSON.weatherForecast[0].area[9].$.forecast; // area[9] is Clementi
});

rest.get(psiURL).on('complete', function(data) {
    psiJSON = data.channel.item[0];

    // region[4] is for West Singapore
    westPSI24 = psiJSON.region[4].record[0].reading[0].$.value;
    westPSI3westPSI3 = psiJSON.region[4].record[0].reading[1].$.value;
});

function getWeather() {
    return 'Clementi weather: ' + clementiNowcast + '\n24 Hour PSI: ' +
        westPSI24 + '\n3 Hour PSI: ' + westPSI3 + '.';
}

module.exports = {
    getWeather: getWeather
};<commit_msg>Update weather methods.<commit_after>var rest = require('restler');
var jf = require('jsonfile');

var neaCredentialsPath = './private/nea_credentials.json';
var neaAuthKey = jf.readFileSync(neaCredentialsPath).key;

var nowcastURL = 'http://www.nea.gov.sg/api/WebAPI?dataset=nowcast&keyref=' +
    neaAuthKey;
var nowcastJSON;
var clementiNowcast;

var psiURL = 'http://www.nea.gov.sg/api/WebAPI/?dataset=psi_update&keyref=' +
    neaAuthKey;
var pm25URL = 'http://www.nea.gov.sg/api/WebAPI/?dataset=pm2.5_update&keyref=' +
    neaAuthKey;
var psiJSON;
var pmJSON;
var westPSI3;
var westPSI24;
var westPM25;
var timeStamp;

function getTime(timeStr) {
    var yy = timeStr.substr(0, 4);
    var MM = timeStr.substr(4, 2);
    var dd = timeStr.substr(6, 2);
    var HH = timeStr.substr(8, 2);
    var mm = timeStr.substr(10, 2);
    var ss = timeStr.substr(12, 2);
    var str = MM + ' ' + dd + ' ' + yy + ' ' + HH + ':' + mm + ':' + ss;
    return new Date(str);
}

rest.get(nowcastURL).on('complete', function(data) {
    nowCastJSON = data.channel.item[0];
    clementiNowcast = nowCastJSON.weatherForecast[0].area[9].$.forecast; // area[9] is Clementi
});

rest.get(psiURL).on('complete', function(data) {
    psiJSON = data.channel.item[0];

    // region[4] is for West Singapore
    westPSI24 = psiJSON.region[4].record[0].reading[0].$.value;
    westPSI3 = psiJSON.region[4].record[0].reading[1].$.value;
});

rest.get(pm25URL).on('complete', function(data) {
    pmJSON = data.channel.item[0];

    // region[4] is for West Singapore
    westPM25 = pmJSON.region[3].record[0].reading[0].$.value;
    timeStamp = pmJSON.region[3].record[0].$.timestamp;
});

function getWeather() {
    return 'Time: ' + getTime(timeStamp) + '\nClementi weather: ' + clementiNowcast + '\n24 Hour PSI: ' +
        westPSI24 + '\n3 Hour PSI: ' + westPSI3 + '\n1 Hour PM 2.5: ' + westPM25 + '.';
}

module.exports = {
    getWeather: getWeather
};
{'fraction_non_alphanumeric': 0.17181906931337454, 'fraction_numerical': 0.02766026684022128, 'mean_word_length': 3.9741100323624594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 5, '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': '7501407', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1160, 'n_words': 207}