obhavouz
Version:
47 lines (37 loc) • 1.25 kB
JavaScript
// const https = require('https');
// https.get('https://restcountries.com/v3.1/name/usa', (res) => {
// let info = '';
// res.on('data', chunk => {
// info += chunk;
// });
// res.on('end', () => {
// const jsonData = JSON.parse(info);
// if (jsonData.status != 404) {
// console.log(jsonData[0].name.common);
// } else {
// console.log("Xato Mavjud!");
// }
// });
// });
const axios = require('axios');
const yargs = require('yargs');
const getWeather = (countryName) => {
axios.get('https://restcountries.com/v3.1/name/' + countryName).then(res => {
var data = res.data[0];
console.log(data.name.common);
var cityName = data.capital[0];
var apiKey = 'b6012df1f1b43c39966b2746429414c2';
axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${apiKey}`).then(resWeather => {
console.log(`Poytaxt: ${cityName}. Ob havo: ${resWeather.data.weather[0].main}`);
})
}).catch(e => console.log("Xato: " + e));
}
yargs.command({
command: "obhavo",
describe: "Ob Havo aniqlaydi",
handler(argumentlar) {
getWeather(argumentlar.davlat);
}
});
yargs.parse();
module.exports = getWeather;