From 656b818488ab4bf2d61e03d557e51c5265f54616 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 5 Dec 2022 08:52:45 -0800 Subject: [PATCH 1/3] Fix conditions map for openmeteo --- src/components/widgets/openmeteo/icon.jsx | 2 +- src/utils/weather/openmeteo-condition-map.js | 212 +++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 src/utils/weather/openmeteo-condition-map.js diff --git a/src/components/widgets/openmeteo/icon.jsx b/src/components/widgets/openmeteo/icon.jsx index a2b01ba19..12d93fcb1 100644 --- a/src/components/widgets/openmeteo/icon.jsx +++ b/src/components/widgets/openmeteo/icon.jsx @@ -1,4 +1,4 @@ -import mapIcon from "utils/weather/owm-condition-map"; +import mapIcon from "utils/weather/openmeteo-condition-map"; export default function Icon({ condition, timeOfDay }) { const IconComponent = mapIcon(condition, timeOfDay); diff --git a/src/utils/weather/openmeteo-condition-map.js b/src/utils/weather/openmeteo-condition-map.js new file mode 100644 index 000000000..06ed3d464 --- /dev/null +++ b/src/utils/weather/openmeteo-condition-map.js @@ -0,0 +1,212 @@ +import * as Icons from "react-icons/wi"; + +// see https://open-meteo.com/en/docs + +const conditions = [ + { + code: 1, + icon: { + day: Icons.WiDayCloudy, + night: Icons.WiNightAltCloudy, + }, + }, + { + code: 2, + icon: { + day: Icons.WiDayCloudy, + night: Icons.WiNightAltCloudy, + }, + }, + { + code: 3, + icon: { + day: Icons.WiDayCloudy, + night: Icons.WiNightAltCloudy, + }, + }, + { + code: 45, + icon: { + day: Icons.WiDayFog, + night: Icons.WiNightFog, + }, + }, + { + code: 48, + icon: { + day: Icons.WiDayFog, + night: Icons.WiNightFog, + }, + }, + { + code: 51, + icon: { + day: Icons.WiDaySprinkle, + night: Icons.WiNightAltSprinkle, + }, + }, + { + code: 53, + icon: { + day: Icons.WiDaySprinkle, + night: Icons.WiNightAltSprinkle, + }, + }, + { + code: 55, + icon: { + day: Icons.WiDaySprinkle, + night: Icons.WiNightAltSprinkle, + }, + }, + { + code: 56, + icon: { + day: Icons.WiDaySleet, + night: Icons.WiNightAltSleet, + }, + }, + { + code: 57, + icon: { + day: Icons.WiDaySleet, + night: Icons.WiNightAltSleet, + }, + }, + { + code: 61, + icon: { + day: Icons.WiDayShowers, + night: Icons.WiNightAltShowers, + }, + }, + { + code: 63, + icon: { + day: Icons.WiDayShowers, + night: Icons.WiNightAltShowers, + }, + }, + { + code: 65, + icon: { + day: Icons.WiDayShowers, + night: Icons.WiNightAltShowers, + }, + }, + { + code: 66, + icon: { + day: Icons.WiDaySleet, + night: Icons.WiNightAltSleet, + }, + }, + { + code: 67, + icon: { + day: Icons.WiDaySleet, + night: Icons.WiNightAltSleet, + }, + }, + { + code: 71, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 73, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 75, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 77, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 80, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 81, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 82, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 85, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 86, + icon: { + day: Icons.WiDaySnow, + night: Icons.WiNightAltSnow, + }, + }, + { + code: 95, + icon: { + day: Icons.WiDayThunderstorm, + night: Icons.WiNightAltThunderstorm, + }, + }, + { + code: 96, + icon: { + day: Icons.WiDayThunderstorm, + night: Icons.WiNightAltThunderstorm, + }, + }, + { + code: 99, + icon: { + day: Icons.WiDayThunderstorm, + night: Icons.WiNightAltThunderstorm, + }, + }, +]; + +export default function mapIcon(weatherStatusCode, timeOfDay) { + const mapping = conditions.find((condition) => condition.code === weatherStatusCode); + console.log(weatherStatusCode, timeOfDay, mapping); + + if (mapping) { + if (timeOfDay === "day") { + return mapping.icon.day; + } + + if (timeOfDay === "night") { + return mapping.icon.night; + } + } + + return Icons.WiDaySunny; +} From 535a7d2f2d3f92235f1ddf5c5cebd9671a01b272 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 5 Dec 2022 09:41:19 -0800 Subject: [PATCH 2/3] Add optional tz --- src/pages/api/widgets/openmeteo.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/api/widgets/openmeteo.js b/src/pages/api/widgets/openmeteo.js index e79931cb6..372336451 100644 --- a/src/pages/api/widgets/openmeteo.js +++ b/src/pages/api/widgets/openmeteo.js @@ -1,8 +1,9 @@ import cachedFetch from "utils/proxy/cached-fetch"; export default async function handler(req, res) { - const { latitude, longitude, units, cache } = req.query; + const { latitude, longitude, units, cache, timezone } = req.query; const degrees = units === "imperial" ? "fahrenheit" : "celsius"; - const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=sunrise,sunset¤t_weather=true&temperature_unit=${degrees}&timezone=auto`; + const timezeone = timezone ?? 'auto' + const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=sunrise,sunset¤t_weather=true&temperature_unit=${degrees}&timezone=${timezeone}`; return res.send(await cachedFetch(apiUrl, cache)); } \ No newline at end of file From a7676c4daa700e5bbcb9b6ba25940f5d1e8baa84 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 5 Dec 2022 09:41:54 -0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9023ae9a..586b44567 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ - Coin Market Cap, Mastodon - Information & Utility Widgets - System Stats (Disk, CPU, Memory) - - Weather via [WeatherAPI.com](https://www.weatherapi.com/), [OpenWeatherMap](https://openweathermap.org/), or [Open-Meteo](https://open-meteo.com/) + - Weather via [OpenWeatherMap](https://openweathermap.org/) or [Open-Meteo](https://open-meteo.com/) - Search Bar - Customizable - 21 theme colors with light and dark mode support