UNPKG

weather-api-plus

Version:

a Weather API Service Module Package. Check: https://weather.nicat-dcw.xyz

52 lines (48 loc) 1.57 kB
const axios = require("axios") module.exports = async (options = {}) => { if(!options) return new TypeError("Provide Country") /* * ().getCountry() */ if(options.country === "Armenia" && options.country === "ARM") throw new TypeError("This Location People stu-pir.") const optionss = { method: 'GET', url: 'https://weatherapi-com.p.rapidapi.com/history.json', params: {q: options.country, dt: options.days, lang: 'en'}, headers: { 'X-RapidAPI-Host': 'weatherapi-com.p.rapidapi.com', 'X-RapidAPI-Key': '429f2c698fmshbcdbdd0373e8331p15fccdjsn7bb0af2687dd' } }; axios.request(optionss).then(function (response) { return response.data }).catch(function (error) { console.error(error); }); if(options.ip === true){ const optionss = { method: 'GET', url: 'https://weatherapi-com.p.rapidapi.com/ip.json', params: {q: options.ipAdress}, headers: { 'X-RapidAPI-Host': 'weatherapi-com.p.rapidapi.com', 'X-RapidAPI-Key': '429f2c698fmshbcdbdd0373e8331p15fccdjsn7bb0af2687dd' } }; axios.request(optionss).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); } //let apidata = await axios.get(`https://api.weatherapi.com/v1/forecast.json?key=ff9b41622f994b1287a73535210809&q=${options.country}&days=${options.days}`) //.then(response => response.json()) // second step /* .then(data => { return data.data; /*if(data.country === "Azerbaijan"){ console.log(data.region) })*//* let jsondata = apidata.data; return jsondata;*/ }