UNPKG

weathers-data-api

Version:

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

38 lines (37 loc) 1.69 kB
const { getWeatherData, getOutfitSuggestion } = require("./testing") exports.getWetherData = async (city) => { try { const weatherData = await getWeatherData(city); const temperature = weatherData.current.temp_c; const temperatureF = weatherData.current.temp_f; const outfit = getOutfitSuggestion(temperature); let is_day if (weatherData.current.is_day == 1) { is_day = "Day" } else { is_day = "Night" } return { status: 200, message: "Weather Data Founded Successfully", city: weatherData.location.name, temperatureC: `${temperature}°C`, temperatureF: `${temperatureF}°F`, humidity: weatherData.current.humidity, is_day: is_day, wind_mphSpeed: `${weatherData.current.wind_mph} miles per hour`, wind_kphSpeed: `${weatherData.current.wind_kph} kilometers per hour`, wind_degree: `${weatherData.current.wind_degree}`, wind_dir: weatherData.current.wind_dir, pressure_mb: `${weatherData.current.pressure_mb} Air pressure (millibar)`, pressure_in: `${weatherData.current.pressure_in} Air pressure (inches)`, VisibilityKm: `${weatherData.current.vis_km} km`, Visibility: `${weatherData.current.vis_miles} miles`, gust_kph: `${weatherData.current.gust_kph} Maximum hawa Speed (kilometers per hour)`, outfitSuggestion: outfit, }; } catch (error) { console.log(error); return { status: 500, error: error.message }; } }