UNPKG

weathers-data-api

Version:

A simple Node.js package to fetch real-time weather data and outfit suggestions based on temperature.

30 lines (26 loc) 1.07 kB
const axios = require("axios"); const API_KEY = "223b215f47fc4480bcd114146252503"; const BASE_URL = "http://api.weatherapi.com/v1/current.json"; const getWeatherData = async (city) => { try { const response = await axios.get(`${BASE_URL}?key=${API_KEY}&q=${city}&aqi=no`); return response.data; } catch (error) { console.log("error",error); return "WeatherAPI se data fetch nahi ho raha."; } }; const getOutfitSuggestion = (temp, weather) => { if (temp > 30) { return "Halki aur airy cotton kapde pehno, sunglasses aur sunscreen use karo."; } else if (temp > 20) { return "T-shirt aur jeans pehno, comfortable footwear ke saath."; } else if (temp > 10) { return "Sweater ya hoodie pehno, halka jacket bhi rakh sakte ho."; } else if (temp > 0) { return "Warm jacket aur boots zaroori hai."; } else { return "Heavy woolen clothes, gloves aur scarf zaroor pehno."; } }; module.exports = { getWeatherData, getOutfitSuggestion };