Skip to content

Instantly share code, notes, and snippets.

@sergiodebcn
Last active March 24, 2017 13:32
Show Gist options
  • Save sergiodebcn/ffca7209c2b86ef1fe91061ebc9ffc60 to your computer and use it in GitHub Desktop.
Save sergiodebcn/ffca7209c2b86ef1fe91061ebc9ffc60 to your computer and use it in GitHub Desktop.
const request = require('request');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What city do you want time data, separate data by comma? ', (cities) => {
var arrayOfCities = cities.split(',');
var numberOfCities = arrayOfCities.length;
var cityResponseCount = 0;
var cityTemperatures = [];
arrayOfCities.forEach(function(city) {
request('http://api.openweathermap.org/data/2.5/weather?q='+city+'&APPID=56113ea64fd73fb989bcfdd636c050f0', function (error, response, body) {
apiResult = JSON.parse(body);
cityResponseCount++;
cityTemperatures[apiResult.name] = apiResult.main.temp;
if (numberOfCities === cityResponseCount){
console.log(cityTemperatures.sort());
}
});
});
rl.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment