Mercurial > hg > egg-tcls
changeset 693:fd45c52d4297
fetch_weather: Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 23 Jun 2023 17:24:32 +0300 |
parents | c262cef9dc54 |
children | bd7f06c8a515 |
files | fetch_weather.pl |
diffstat | 1 files changed, 9 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/fetch_weather.pl Thu Jun 22 15:47:45 2023 +0300 +++ b/fetch_weather.pl Fri Jun 23 17:24:32 2023 +0300 @@ -331,15 +331,13 @@ my $res = fetch_http($uri); if ($res->code >= 200 && $res->code <= 201) { - my $json_str = force_decode_utf8($res->decoded_content); - my $data = JSON->new->decode($json_str); + my $data_json = JSON->new->decode(force_decode_utf8($res->decoded_content)); - print $json_str if opt_chk_bool("dump"); + print Dumper($data_json) if opt_chk_bool("dump"); - if (!defined($data->{"dataUpdatedTime"}) || !defined($data->{"stations"})) + if (!defined($data_json->{"dataUpdatedTime"}) || !defined($data_json->{"stations"})) { print STDERR "ERROR: REST/JSON call result did not contain required data.\n"; - print STDERR $json_str."\n\n"; } else { @@ -370,18 +368,18 @@ # Parse the data .. my $meta_data = {}; - my $json = JSON->new->decode($meta_str); + my $meta_json = JSON->new->decode($meta_str); - print $meta_str if opt_chk_bool("dump"); + print Dumper($meta_json) if opt_chk_bool("dump"); if ($fetch_meta) { # Save new cache, in more optimal form, if needed. print STDERR "Storing to cache '".$meta_file."'.\n" if (opt_get_int("debug") > 0); - write_binary($meta_file, JSON->new->utf8->encode($json)); + write_binary($meta_file, JSON->new->utf8->encode($meta_json)); } - foreach my $ms (@{$json->{"features"}}) + foreach my $ms (@{$meta_json->{"features"}}) { # Filter functional stations? if (defined($ms->{"properties"}) && @@ -395,7 +393,7 @@ } my $nrecords = 0; - foreach my $wdata (@{$data->{"stations"}}) + foreach my $wdata (@{$data_json->{"stations"}}) { my $wid = $wdata->{"id"}; if (defined($meta_data->{$wid}) && @@ -472,7 +470,7 @@ my $xml = XMLin(force_decode_utf8($res->decoded_content)); my $time_base = time(); - print $res->decoded_content if opt_chk_bool("dump"); + print Dumper($xml) if opt_chk_bool("dump"); if (defined($xml->{"wfs:member"}{"omso:GridSeriesObservation"})) {