changeset 447:11124f9bf994

fetch_weather: Instead of checking the latest static metadata update timestamp against the weather data XML, have a setting of days until the metadata is considered stale. This is because the new REST/JSON API does not provide the metadata updated timestamp anymore.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 28 Sep 2017 15:19:09 +0300
parents ba559d5d44db
children ac3b79eca0ca
files config.fetch_weather.example fetch_weather.pl
diffstat 2 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/config.fetch_weather.example	Thu Sep 28 15:17:39 2017 +0300
+++ b/config.fetch_weather.example	Thu Sep 28 15:19:09 2017 +0300
@@ -22,6 +22,9 @@
 ## Tiehallinto static meta data file + path
 tiehallinto_meta = "/some/path/weather.tiehallinto.meta"
 
+# Fetch period for static meta data (in days)
+tiehallinto_meta_period = 7
+
 ##
 ## Enable/disable open data access from FMI
 ## You will need to obtain an API key, refer to
--- a/fetch_weather.pl	Thu Sep 28 15:17:39 2017 +0300
+++ b/fetch_weather.pl	Thu Sep 28 15:19:09 2017 +0300
@@ -45,6 +45,7 @@
   "http_user_agent" => "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 6.0) Opera 10.63  [en]",
   "tiehallinto_rw_url" => "http://tie.digitraffic.fi/sujuvuus/ws/roadWeather",
   "tiehallinto_meta" => "tiehallinto.meta",
+  "tiehallinto_meta_period" => 7,
   "tiehallinto_meta_url" => "http://tie.digitraffic.fi/api/v1/metadata/weather-stations",
 );
 
@@ -372,16 +373,9 @@
       my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"};
 
       # Check if we need to update the static meta data
-      my $fetch_meta = (-e $meta_file) ? 0 : 1;
-
-      if (defined($data->{"laststaticdataupdate"}))
-      {
-        # Compare metadata cache file modification timestamp to info in XML
-        my $tmp1 = str2time($data->{"laststaticdataupdate"});
-        my $tmp2 = (-e $meta_file) ? (stat($meta_file))[9] : -1;
-        $fetch_meta = 1 unless ($tmp1 < $tmp2);
-      }
       my $meta_file = opt_get("tiehallinto_meta");
+      my $meta_stamp = (-e $meta_file) ? (stat($meta_file))[9] : -1;
+      my $fetch_meta = ($meta_stamp + 60*60*24 * opt_get_int("tiehallinto_meta_period")) < time();
 
       # Fetch or read the cache
       my $meta_str;