From: Yves-Alexis Perez <corsac@debian.org>
Date: Sun, 18 Apr 2021 19:12:09 +0200
Subject: port weather plugin to 2.0 met.no API

---
 panel-plugin/weather.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index c096795..55fe151 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -578,8 +578,8 @@ update_handler(plugin_data *data)
 {
     gchar *url;
     gboolean night_time;
-    time_t now_t, end_t;
-    struct tm now_tm, end_tm;
+    time_t now_t;
+    struct tm now_tm;
 
     g_assert(data != NULL);
     if (G_UNLIKELY(data == NULL))
@@ -614,22 +614,16 @@ update_handler(plugin_data *data)
         data->astro_update->next = time_calc_hour(now_tm, 1);
         data->astro_update->started = TRUE;
 
-        /* calculate date range for request */
-        end_t = time_calc_day(now_tm, ASTRODATA_MAX_DAYS);
-        end_tm = *localtime(&end_t);
-
         /* build url */
-        url = g_strdup_printf("https://api.met.no/weatherapi/sunrise/1.1/?"
-                              "lat=%s;lon=%s;"
-                              "from=%04d-%02d-%02d;"
-                              "to=%04d-%02d-%02d",
+        url = g_strdup_printf("https://api.met.no/weatherapi"
+                              "/sunrise/2.0/?lat=%s&lon=%s&"
+                              "date=%04d-%02d-%02d&"
+                              "offset=00:00&days=%u",
                               data->lat, data->lon,
                               now_tm.tm_year + 1900,
                               now_tm.tm_mon + 1,
                               now_tm.tm_mday,
-                              end_tm.tm_year + 1900,
-                              end_tm.tm_mon + 1,
-                              end_tm.tm_mday);
+                              data->forecast_days);
 
         /* start receive thread */
         g_message(_("getting %s"), url);
@@ -645,10 +639,11 @@ update_handler(plugin_data *data)
         data->weather_update->started = TRUE;
 
         /* build url */
-        url =
-            g_strdup_printf("https://api.met.no/weatherapi"
-                            "/locationforecastlts/1.3/?lat=%s;lon=%s;msl=%d",
-                            data->lat, data->lon, data->msl);
+        url = g_strdup_printf("https://api.met.no"
+                              "/weatherapi/locationforecast/%s/"
+                              "classic?lat=%s&lon=%s&altitude=%d",
+                              "2.0",
+                              data->lat, data->lon, data->msl);
 
         /* start receive thread */
         g_message(_("getting %s"), url);
