Last active
March 24, 2017 13:32
-
-
Save sergiodebcn/ffca7209c2b86ef1fe91061ebc9ffc60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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