UNPKG

weathers-data

Version:

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

34 lines (31 loc) 1.21 kB
const axios = require("axios"); const API_KEY = "5b8a1d184633b8052056a3ceff4c53bf"; // Yahan apni API key daalna const BASE_URL = "https://api.openweathermap.org/data/2.5/weather"; const getWeatherData = async (city) => { try { const response = await axios.get(`${BASE_URL}`, { params: { q: city, appid: API_KEY, units: "metric", // Celsius temperature ke liye }, }); return response.data; } catch (error) { return "OpenWeather API 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 };