Mercurial > hg > egg-tcls
changeset 406:4c3abf052d01
fetch_weather: "use 5.018;" and some cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Jan 2017 04:15:27 +0200 |
parents | 26c613434971 |
children | b05da2077e44 |
files | fetch_weather.pl |
diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/fetch_weather.pl Fri Jan 06 21:20:52 2017 +0200 +++ b/fetch_weather.pl Sat Jan 07 04:15:27 2017 +0200 @@ -15,6 +15,7 @@ # # ########################################################################## +use 5.018; use strict; use warnings; use utf8; @@ -63,7 +64,8 @@ my $req = HTTP::Request->new(GET => $_[0]); $req->header('Accept-Encoding' => scalar HTTP::Message::decodable()); - return $agent->request($req); + my $res = $agent->request($req); + return $res; } @@ -308,6 +310,7 @@ if (opt_chk_bool("opt_tiehallinto")) { my $uri = "http://tie.digitraffic.fi/sujuvuus/ws/roadWeather"; + print STDERR "Fetching Tiehallinto road weather data from ".$uri."\n" if (opt_get_int("debug") > 0); my $res = fetch_http($uri); if ($res->code >= 200 && $res->code <= 201) { @@ -320,8 +323,8 @@ } else { + # Parse the XML my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"}; - print STDERR "Checking Tiehallinto response from ".$uri."\n" if (opt_get_int("debug") > 0); # Check if we need to update the static meta data my $meta_file = opt_get("tiehallinto_static_meta"); @@ -339,8 +342,8 @@ my $meta_str; if ($fetch_meta || $force_update) { - print STDERR "Fetching Tiehallinto static meta data.\n" if (opt_get_int("debug") > 0); my $uri = "https://raw.githubusercontent.com/finnishtransportagency/metadata/master/csv/meta_rws_stations.csv"; + print STDERR "Fetching Tiehallinto static meta data from $uri\n" if (opt_get_int("debug") > 1); my $res = fetch_http($uri); die("Failed to fetch $uri data.\n") unless ($res->code <= 200 && $res->code <= 201); @@ -351,7 +354,7 @@ else { print STDERR "Using CACHED Tiehallinto static meta data from '$meta_file'.\n" if (opt_get_int("debug") > 0); - $meta_str = read_text($meta_file, "utf8"); + $meta_str = read_text($meta_file, "utf-8"); } # Parse the data ..