# HG changeset patch # User Matti Hamalainen # Date 1506601149 -10800 # Node ID 11124f9bf99422d0b4eae1fbe2a230c5418898a4 # Parent ba559d5d44db4f957bc2f00624f756264d191995 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. diff -r ba559d5d44db -r 11124f9bf994 config.fetch_weather.example --- 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 diff -r ba559d5d44db -r 11124f9bf994 fetch_weather.pl --- 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;