fetchweather
Version:
You can get Countries Capital's Weather via Country name
26 lines (22 loc) • 844 B
JavaScript
const axios = require('axios');
const yargs = require('yargs');
const getWeather = (countryName) => {
axios.get('https://restcountries.com/v3.1/name/' + countryName).then(res => {
let data = res.data[0];
console.log(data.name.common);
let cityName = data.capital[0];
let apiKey = '44eef6f9ce88a4a4c25fc3c60bfaeaa5';
axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${apiKey}`).then(resWeather => {
console.log(`Capital: ${cityName}. Weather: ${resWeather.data.weather[0].main}`);
});
}).catch(e => console.log('Error: ' + e));
}
yargs.command({
command: 'getWeather',
describe: 'You can get countries weather !',
handler(argumentlar) {
getWeather(argumentlar.country);
}
});
yargs.parse();
module.exports = getWeather;