comparison fetch_weather.pl @ 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
comparison
equal deleted inserted replaced
446:ba559d5d44db 447:11124f9bf994
43 "fmi_api_key" => "", 43 "fmi_api_key" => "",
44 "outfile" => "", 44 "outfile" => "",
45 "http_user_agent" => "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 6.0) Opera 10.63 [en]", 45 "http_user_agent" => "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 6.0) Opera 10.63 [en]",
46 "tiehallinto_rw_url" => "http://tie.digitraffic.fi/sujuvuus/ws/roadWeather", 46 "tiehallinto_rw_url" => "http://tie.digitraffic.fi/sujuvuus/ws/roadWeather",
47 "tiehallinto_meta" => "tiehallinto.meta", 47 "tiehallinto_meta" => "tiehallinto.meta",
48 "tiehallinto_meta_period" => 7,
48 "tiehallinto_meta_url" => "http://tie.digitraffic.fi/api/v1/metadata/weather-stations", 49 "tiehallinto_meta_url" => "http://tie.digitraffic.fi/api/v1/metadata/weather-stations",
49 ); 50 );
50 51
51 52
52 ### 53 ###
370 { 371 {
371 # Parse the XML 372 # Parse the XML
372 my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"}; 373 my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"};
373 374
374 # Check if we need to update the static meta data 375 # Check if we need to update the static meta data
375 my $fetch_meta = (-e $meta_file) ? 0 : 1;
376
377 if (defined($data->{"laststaticdataupdate"}))
378 {
379 # Compare metadata cache file modification timestamp to info in XML
380 my $tmp1 = str2time($data->{"laststaticdataupdate"});
381 my $tmp2 = (-e $meta_file) ? (stat($meta_file))[9] : -1;
382 $fetch_meta = 1 unless ($tmp1 < $tmp2);
383 }
384 my $meta_file = opt_get("tiehallinto_meta"); 376 my $meta_file = opt_get("tiehallinto_meta");
377 my $meta_stamp = (-e $meta_file) ? (stat($meta_file))[9] : -1;
378 my $fetch_meta = ($meta_stamp + 60*60*24 * opt_get_int("tiehallinto_meta_period")) < time();
385 379
386 # Fetch or read the cache 380 # Fetch or read the cache
387 my $meta_str; 381 my $meta_str;
388 if ($fetch_meta || opt_chk_bool("force_update")) 382 if ($fetch_meta || opt_chk_bool("force_update"))
389 { 383 {