[libgweather/gnome-3-36] weather: Work-around current weather not being available
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/gnome-3-36] weather: Work-around current weather not being available
- Date: Fri, 19 Jun 2020 14:43:07 +0000 (UTC)
commit 94a662f383f6495ddb5f847b3a8a9a78110149f9
Author: Bastien Nocera <hadess hadess net>
Date: Fri Jun 19 12:21:31 2020 +0200
weather: Work-around current weather not being available
When the current weather isn't available, such as when the NOAA METAR
servers aren't working correctly, use the first forecast available if
it's a forecast for less than an hour in the future.
Closes: #44
libgweather/gweather-weather.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 2ac0cd07..17c3612f 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -343,6 +343,32 @@ copy_weather_data (GWeatherInfo *src,
dest->priv->visibility = src->priv->visibility;
}
+static void
+fixup_current_conditions (GWeatherInfo *info)
+{
+ GWeatherInfo *first_forecast;
+
+ /* Current conditions already available */
+ if (info->priv->update != 0) {
+ g_debug ("Not fixing up current conditions, already valid");
+ return;
+ } else if (!info->priv->forecast_list ||
+ !info->priv->forecast_list->data) {
+ g_debug ("No forecast list available, not fixing up");
+ return;
+ }
+
+ first_forecast = info->priv->forecast_list->data;
+ /* Add current conditions from forecast if close enough */
+ if (first_forecast->priv->update - time(NULL) > 60 * 60) {
+ g_debug ("Forecast is too far in the future, ignoring");
+ return;
+ }
+
+ copy_weather_data (first_forecast, info);
+ g_debug ("Fixed up missing current weather with first forecast data");
+}
+
void
_gweather_info_request_done (GWeatherInfo *info,
SoupMessage *message)
@@ -350,11 +376,13 @@ _gweather_info_request_done (GWeatherInfo *info,
info->priv->requests_pending = g_slist_remove (info->priv->requests_pending, message);
g_object_ref (message);
- if (info->priv->requests_pending == NULL)
+ if (info->priv->requests_pending == NULL) {
+ fixup_current_conditions (info);
g_signal_emit (info, gweather_info_signals[SIGNAL_UPDATED], 0);
- else
+ } else {
g_debug ("Not emitting 'updated' as there are still %d requests pending",
g_slist_length (info->priv->requests_pending));
+ }
}
/* it's OK to pass in NULL */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]