UNPKG

ob-havo-by-ibrohim

Version:

Sizga ob havoni ko'rsatib beradi

56 lines (41 loc) 1.52 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.official); // } // 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]; var cityName = data.capital[0]; var apiKey = '44eef69ce88a4a4c25fc3c60bfaeaa5'; axios.get(`http://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 havo lob kelib beraman', handler(argvs){ getWeather(argvs.country); } }); yargs.parse(); module.exports = getWeather; // const obhavonibilibber = require('obhavonibilibber'); // obhavonibilibber("Uzbekistan"); // 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=646ef45a7058b3651358a4d0eddaecfa' // 'api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key}'