[Xfce4-commits] <xfce4-weather-plugin:master> Clean up old weather data.
Harald Judt
noreply at xfce.org
Sun Dec 9 23:44:12 CET 2012
Updating branch refs/heads/master
to 189bb0d6f014fafdaadb0f6b5e45ca395d37ae61 (commit)
from 4b609e943be937964aa92cef313a7dcfd5e018eb (commit)
commit 189bb0d6f014fafdaadb0f6b5e45ca395d37ae61
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Dec 9 19:24:24 2012 +0100
Clean up old weather data.
Data older than a day will be removed from the timeslices array.
panel-plugin/weather-parsers.c | 32 ++++++++++++++++++++++++++++++++
panel-plugin/weather-parsers.h | 4 ++++
panel-plugin/weather.c | 7 +++++--
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 08ef607..187ef3d 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -45,6 +45,9 @@
(xmlStrEqual(node->name, (const xmlChar *) type))
+extern debug_mode;
+
+
/*
* This is a portable replacement for the deprecated timegm(),
* copied from the man page and modified to use GLIB functions.
@@ -605,6 +608,35 @@ xml_weather_free(xml_weather *wd)
void
+xml_weather_clean(xml_weather *wd)
+{
+ xml_time *timeslice;
+ time_t now_t = time(NULL);
+ guint i;
+
+ if (G_UNLIKELY(wd == NULL || wd->timeslices == NULL))
+ return;
+ for (i = 0; i < wd->timeslices->len; i++) {
+ timeslice = g_array_index(wd->timeslices, xml_time*, i);
+ if (G_UNLIKELY(timeslice == NULL))
+ continue;
+ if (difftime(now_t, timeslice->end) > DATA_EXPIRY_TIME) {
+ if (debug_mode) {
+ gchar *start, *end;
+ start = weather_debug_strftime_t(timeslice->start);
+ end = weather_debug_strftime_t(timeslice->end);
+ weather_debug("Removing expired timeslice [%s - %s].");
+ g_free(start);
+ g_free(end);
+ }
+ xml_time_free(timeslice);
+ g_array_remove_index(wd->timeslices, i--);
+ }
+ }
+}
+
+
+void
xml_astro_free(xml_astro *astro)
{
g_assert(astro != NULL);
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 327d43c..bd377eb 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -24,6 +24,8 @@
#include <libxml/parser.h>
#include <libsoup/soup.h>
+#define DATA_EXPIRY_TIME (24 * 3600)
+
G_BEGIN_DECLS
enum {
@@ -145,6 +147,8 @@ void xml_time_free(xml_time *timeslice);
void xml_weather_free(xml_weather *wd);
+void xml_weather_clean(xml_weather *wd);
+
void xml_astro_free(xml_astro *astro);
void xml_geolocation_free(xml_geolocation *geo);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index c60634b..5eb0c88 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -276,11 +276,12 @@ update_current_conditions(xfceweather_data *data)
xml_time_free(data->weatherdata->current_conditions);
data->weatherdata->current_conditions = NULL;
}
-
- data->last_conditions_update = time(NULL);
+ /* set time of last update to now, but exact only to the minute */
+ time(&data->last_conditions_update);
now_tm = *localtime(&data->last_conditions_update);
now_tm.tm_sec = 0;
data->last_conditions_update = mktime(&now_tm);
+
data->weatherdata->current_conditions =
make_current_conditions(data->weatherdata,
data->last_conditions_update);
@@ -319,6 +320,7 @@ cb_weather_update(SoupSession *session,
xmlDoc *doc;
xmlNode *root_node;
+ weather_debug("Processing downloaded weather data.");
doc = get_xml_document(msg);
if (G_LIKELY(doc)) {
root_node = xmlDocGetRootElement(doc);
@@ -328,6 +330,7 @@ cb_weather_update(SoupSession *session,
}
xmlFreeDoc(doc);
}
+ xml_weather_clean(data->weatherdata);
weather_debug("Updating current conditions.");
update_current_conditions(data);
weather_dump(weather_dump_weatherdata, data->weatherdata);
More information about the Xfce4-commits
mailing list