UNPKG

obhavonibilibber

Version:

Bu paket sizga davlat nomi orqali ob havoni chiqarib beradi !

42 lines (39 loc) 1.27 kB
/* const https = require('https'); https.get('https://restcountries.com/v3.1/name/uzbekistan', (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 = '44eef6f9ce88a4a4c25fc3c60bfaeaa5'; axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${apiKey}`).then(resWeather => { console.log(`Poytaxt: ${cityName}. ObHavo: ${resWeather.data.weather[0].main}`); }); }).catch(e => console.log("XATO: " + e)); } yargs.command({ command: 'getWeather', describe: 'Ob Havoni Olib Kelib Beradi !', handler(argumentlar) { getWeather(argumentlar.country); } }); yargs.parse(); module.exports = getWeather;