Skip to content

Commit

Permalink
Migrate OpenWeather to Open-Meteo
Browse files Browse the repository at this point in the history
OpenWeather Call API is no longer free.
  • Loading branch information
darekkay committed Aug 13, 2024
1 parent c0c4b5f commit 4b8be9f
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 456 deletions.
33 changes: 14 additions & 19 deletions app/src/api/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,22 @@ export interface UnsplashImage {
altText?: string;
[key: string]: any;
}
export declare enum WeatherIcon {
Sun = "sun",
CloudSun = "cloud-sun",
CloudSunRain = "cloud-sun-rain",
Moon = "moon",
CloudMoon = "cloud-moon",
CloudMoonRain = "cloud-moon-rain",
Clouds = "clouds",
CloudShowers = "cloud-showers",
Thunderstorm = "thunderstorm",
Snow = "snow",
Fog = "fog",
}
export interface WeatherCondition {
description: string;
icon:
| "01d"
| "02d"
| "03d"
| "04d"
| "09d"
| "10d"
| "11d"
| "13d"
| "50d"
| "01n"
| "02n"
| "03n"
| "04n"
| "09n"
| "10n"
| "11n"
| "13n"
| "50n";
icon: WeatherIcon;
[key: string]: any;
}
export interface WeatherData {
Expand Down
14 changes: 14 additions & 0 deletions app/src/api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
* ---------------------------------------------------------------
*/

export var WeatherIcon;
(function (WeatherIcon) {
WeatherIcon["Sun"] = "sun";
WeatherIcon["CloudSun"] = "cloud-sun";
WeatherIcon["CloudSunRain"] = "cloud-sun-rain";
WeatherIcon["Moon"] = "moon";
WeatherIcon["CloudMoon"] = "cloud-moon";
WeatherIcon["CloudMoonRain"] = "cloud-moon-rain";
WeatherIcon["Clouds"] = "clouds";
WeatherIcon["CloudShowers"] = "cloud-showers";
WeatherIcon["Thunderstorm"] = "thunderstorm";
WeatherIcon["Snow"] = "snow";
WeatherIcon["Fog"] = "fog";
})(WeatherIcon || (WeatherIcon = {}));
import axios from "axios";
export var ContentType;
(function (ContentType) {
Expand Down
62 changes: 22 additions & 40 deletions app/src/components/icon/custom/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import { ReactComponent as Cloud } from "./weather/cloud.svg";
import { ReactComponent as Clouds } from "./weather/clouds.svg";
import { ReactComponent as CloudMoon } from "./weather/cloud-moon.svg";
import { ReactComponent as CloudMoonRain } from "./weather/cloud-moon-rain.svg";
Expand All @@ -14,50 +13,33 @@ import { ReactComponent as Sun } from "./weather/sun.svg";
import { ReactComponent as Thunderstorm } from "./weather/thunderstorm.svg";

export type CustomIconName =
| "01d"
| "02d"
| "03d"
| "04d"
| "09d"
| "10d"
| "11d"
| "13d"
| "50d"
| "01n"
| "02n"
| "03n"
| "04n"
| "09n"
| "10n"
| "11n"
| "13n"
| "50n";
| "sun"
| "cloud-sun"
| "cloud-sun-rain"
| "moon"
| "cloud-moon"
| "cloud-moon-rain"
| "clouds"
| "cloud-showers"
| "thunderstorm"
| "snow"
| "fog";

const icons: Record<
CustomIconName,
React.FunctionComponent<React.SVGProps<SVGSVGElement>>
> = {
// day variants
"01d": Sun,
"02d": CloudSun,
"03d": Cloud,
"04d": Clouds,
"09d": CloudShowers,
"10d": CloudSunRain,
"11d": Thunderstorm,
"13d": Snow,
"50d": Fog,

// night variants
"01n": Moon,
"02n": CloudMoon,
"03n": Cloud,
"04n": Clouds,
"09n": CloudShowers,
"10n": CloudMoonRain,
"11n": Thunderstorm,
"13n": Snow,
"50n": Fog,
sun: Sun,
"cloud-sun": CloudSun,
"cloud-sun-rain": CloudSunRain,
moon: Moon,
"cloud-moon": CloudMoon,
"cloud-moon-rain": CloudMoonRain,
clouds: Clouds,
"cloud-showers": CloudShowers,
thunderstorm: Thunderstorm,
snow: Snow,
fog: Fog,
};

export default icons;
1 change: 0 additions & 1 deletion app/src/components/icon/custom/weather/cloud.svg

This file was deleted.

31 changes: 12 additions & 19 deletions app/src/widgets/weather/__stories__/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@ export default {
};

const weatherIcons = [
"01d",
"02d",
"03d",
"04d",
"09d",
"10d",
"11d",
"13d",
"50d",
"01n",
"02n",
"03n",
"04n",
"09n",
"10n",
"11n",
"13n",
"50n",
"sun",
"cloud-sun",
"cloud-sun-rain",
"moon",
"cloud-moon",
"cloud-moon-rain",
"clouds",
"cloud-showers",
"thunderstorm",
"snow",
"fog",
] as const;

const createForecast = () => {
Expand Down Expand Up @@ -69,7 +62,7 @@ export const Variants = () => {
temperature: 24,
condition: {
description: "clear sky",
icon: "01d",
icon: "sun",
},
},
forecast: createForecast(),
Expand Down
5 changes: 3 additions & 2 deletions app/src/widgets/weather/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";

import { render, screen } from "common/testing";
import { widgetContentProps, widgetStatusDisplay } from "common/utils/mock";
import type { WeatherIcon } from "api";

import Weather from "../index";

Expand All @@ -12,15 +13,15 @@ const commonProps = {
temperature: 24,
condition: {
description: "clear sky",
icon: "01d" as const,
icon: "sun" as WeatherIcon,
},
},
forecast: [
{
date: 1598180400,
condition: {
description: "overcast clouds",
icon: "04d" as const,
icon: "clouds" as WeatherIcon,
},
temperatureMin: 18,
temperatureMax: 30,
Expand Down
9 changes: 9 additions & 0 deletions app/src/widgets/weather/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const Configuration = ({
}
options={["metric", "imperial"] as const}
/>
<div className="text-right text-1">
<Trans
i18nKey="common.poweredBy"
values={{ name: "Open-Meteo" }}
components={{
alink: <Link href="https://open-meteo.com/">{""}</Link>,
}}
/>
</div>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current development

- :boom: Remove Twitter integration.
- :boom: Switch from OpenWeather to [[Open-Meteo](https://open-meteo.com).
- :boom: Drop Node 16 support.
- :sparkles: New widget: [Weather](https://dashboard.darekkay.com/docs/widgets/weather.html).
- :sparkles: New widget: [Day Countdown](https://dashboard.darekkay.com/docs/widgets/day-countdown.html).
Expand Down
1 change: 0 additions & 1 deletion docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Recommended:
Some widgets require a 3rd-party API key:

- [Unsplash](https://unsplash.com/documentation)
- [OpenWeatherMap](https://openweathermap.org/api)
- [YouTube](https://developers.google.com/youtube/v3/getting-started)

Those keys need to be stored at `server/.env` (copy `server/.env.example` as a template). The project will run with missing API keys, but the affected widgets will not work.
Expand Down
1 change: 0 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
SAVE_AXIOS_RESPONSES=false
API_OPEN_WEATHER_MAP=
API_UNSPLASH=
API_YOUTUBE=
1 change: 0 additions & 1 deletion server/.env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
API_OPEN_WEATHER_MAP=mock-api-key
API_UNSPLASH=mock-api-key
API_YOUTUBE=mock-api-key
7 changes: 6 additions & 1 deletion server/src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ const models: TsoaRoute.Models = {
"additionalProperties": true,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"WeatherIcon": {
"dataType": "refAlias",
"type": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["sun"]},{"dataType":"enum","enums":["cloud-sun"]},{"dataType":"enum","enums":["cloud-sun-rain"]},{"dataType":"enum","enums":["moon"]},{"dataType":"enum","enums":["cloud-moon"]},{"dataType":"enum","enums":["cloud-moon-rain"]},{"dataType":"enum","enums":["clouds"]},{"dataType":"enum","enums":["cloud-showers"]},{"dataType":"enum","enums":["thunderstorm"]},{"dataType":"enum","enums":["snow"]},{"dataType":"enum","enums":["fog"]}],"validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"WeatherCondition": {
"dataType": "refObject",
"properties": {
"description": {"dataType":"string","required":true},
"icon": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["01d"]},{"dataType":"enum","enums":["02d"]},{"dataType":"enum","enums":["03d"]},{"dataType":"enum","enums":["04d"]},{"dataType":"enum","enums":["09d"]},{"dataType":"enum","enums":["10d"]},{"dataType":"enum","enums":["11d"]},{"dataType":"enum","enums":["13d"]},{"dataType":"enum","enums":["50d"]},{"dataType":"enum","enums":["01n"]},{"dataType":"enum","enums":["02n"]},{"dataType":"enum","enums":["03n"]},{"dataType":"enum","enums":["04n"]},{"dataType":"enum","enums":["09n"]},{"dataType":"enum","enums":["10n"]},{"dataType":"enum","enums":["11n"]},{"dataType":"enum","enums":["13n"]},{"dataType":"enum","enums":["50n"]}],"required":true},
"icon": {"ref":"WeatherIcon","required":true},
},
"additionalProperties": true,
},
Expand Down
38 changes: 17 additions & 21 deletions server/src/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,29 @@
"type": "object",
"additionalProperties": true
},
"WeatherIcon": {
"type": "string",
"enum": [
"sun",
"cloud-sun",
"cloud-sun-rain",
"moon",
"cloud-moon",
"cloud-moon-rain",
"clouds",
"cloud-showers",
"thunderstorm",
"snow",
"fog"
]
},
"WeatherCondition": {
"properties": {
"description": {
"type": "string"
},
"icon": {
"type": "string",
"enum": [
"01d",
"02d",
"03d",
"04d",
"09d",
"10d",
"11d",
"13d",
"50d",
"01n",
"02n",
"03n",
"04n",
"09n",
"10n",
"11n",
"13n",
"50n"
]
"$ref": "#/components/schemas/WeatherIcon"
}
},
"required": [
Expand Down
1 change: 0 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const config = {
port: process.env.PORT ?? 3401,
saveAxiosResponses: process.env.SAVE_AXIOS_RESPONSES === "true",
api: {
openWeatherMap: process.env.API_OPEN_WEATHER_MAP,
unsplash: process.env.API_UNSPLASH,
youtube: process.env.API_YOUTUBE,
},
Expand Down
Loading

0 comments on commit 4b8be9f

Please sign in to comment.