Mercurial > hg > egg-tcls
comparison fetch_weather.pl @ 680:053d5662bb16
fetch_weather: Add commandline option to dump the received raw data in stdout.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 23 May 2021 13:26:15 +0300 |
parents | 14dfb925a64a |
children | 7f1a0d25aa40 |
comparison
equal
deleted
inserted
replaced
679:c95c0eb0a10f | 680:053d5662bb16 |
---|---|
37 ### Configuration settings | 37 ### Configuration settings |
38 ### | 38 ### |
39 my %settings = ( | 39 my %settings = ( |
40 "force_update" => 0, | 40 "force_update" => 0, |
41 "debug" => 0, | 41 "debug" => 0, |
42 "dump" => 0, | |
42 "opt_fmi" => 0, | 43 "opt_fmi" => 0, |
43 "opt_tiehallinto" => 0, | 44 "opt_tiehallinto" => 0, |
44 "purge_threshold" => 60, | 45 "purge_threshold" => 60, |
45 "outfile" => "", | 46 "outfile" => "", |
46 "http_user_agent" => "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 6.0) Opera 10.63 [en]", | 47 "http_user_agent" => "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 6.0) Opera 10.63 [en]", |
274 } | 275 } |
275 elsif ($arg eq "-debug") | 276 elsif ($arg eq "-debug") |
276 { | 277 { |
277 $settings{"debug"} = 1; | 278 $settings{"debug"} = 1; |
278 } | 279 } |
280 elsif ($arg eq "-dump") | |
281 { | |
282 $settings{"dump"} = 1; | |
283 } | |
279 else | 284 else |
280 { | 285 { |
281 die("Configuration file already specified!\n") if defined($opt_cfgfile); | 286 die("Configuration file already specified!\n") if defined($opt_cfgfile); |
282 $opt_cfgfile = $arg; | 287 $opt_cfgfile = $arg; |
283 } | 288 } |
289 "Weather Fetch v1.0 by ccr/TNSP <ccr\@tnsp.org>\n". | 294 "Weather Fetch v1.0 by ccr/TNSP <ccr\@tnsp.org>\n". |
290 "Usage: $0 <config file> [options]\n". | 295 "Usage: $0 <config file> [options]\n". |
291 "\n". | 296 "\n". |
292 " -force : Force updating of all data\n". | 297 " -force : Force updating of all data\n". |
293 " -debug : Enable debug\n". | 298 " -debug : Enable debug\n". |
299 " -dump : Dump received raw data\n". | |
294 "\n" | 300 "\n" |
295 ); | 301 ); |
296 } | 302 } |
297 | 303 |
298 opt_read_config($opt_cfgfile) == 0 or die("Errors while parsing configuration file '".$opt_cfgfile."'.\n"); | 304 opt_read_config($opt_cfgfile) == 0 or die("Errors while parsing configuration file '".$opt_cfgfile."'.\n"); |
335 if ($res->code >= 200 && $res->code <= 201) | 341 if ($res->code >= 200 && $res->code <= 201) |
336 { | 342 { |
337 my $json_str = force_decode_utf8($res->decoded_content); | 343 my $json_str = force_decode_utf8($res->decoded_content); |
338 my $data = JSON->new->decode($json_str); | 344 my $data = JSON->new->decode($json_str); |
339 | 345 |
340 #print $json_str."\n"; die("\n"); | 346 print $json_str if opt_chk_bool("dump"); |
341 | 347 |
342 if (!defined($data->{"dataUpdatedTime"}) || !defined($data->{"weatherStations"})) | 348 if (!defined($data->{"dataUpdatedTime"}) || !defined($data->{"weatherStations"})) |
343 { | 349 { |
344 print STDERR "ERROR: REST/JSON call result did not contain required data.\n"; | 350 print STDERR "ERROR: REST/JSON call result did not contain required data.\n"; |
345 print STDERR $json_str."\n\n"; | 351 print STDERR $json_str."\n\n"; |
443 ### | 449 ### |
444 ### Fetch FMI data | 450 ### Fetch FMI data |
445 ### | 451 ### |
446 if (opt_chk_bool("opt_fmi")) | 452 if (opt_chk_bool("opt_fmi")) |
447 { | 453 { |
448 my @fmitems = ("temperature", "humidity", "windspeedms", "winddirection", "totalcloudcover"); | 454 my @fmitems = ( |
455 "temperature", "humidity", "windspeedms", | |
456 "winddirection", "totalcloudcover", | |
457 ); | |
449 | 458 |
450 my $uri = opt_get("fmi_weather_base_url"). | 459 my $uri = opt_get("fmi_weather_base_url"). |
451 "?request=getFeature". | 460 "?request=getFeature". |
452 "&storedquery_id=fmi::observations::weather::multipointcoverage". | 461 "&storedquery_id=fmi::observations::weather::multipointcoverage". |
453 "&starttime=".format_time_gmt(time() - 10*60)."&endtime=".format_time_gmt(time()). | 462 "&starttime=".format_time_gmt(time() - 10*60)."&endtime=".format_time_gmt(time()). |
460 if ($res->code >= 200 && $res->code <= 201) | 469 if ($res->code >= 200 && $res->code <= 201) |
461 { | 470 { |
462 my $xml = XMLin(force_decode_utf8($res->decoded_content)); | 471 my $xml = XMLin(force_decode_utf8($res->decoded_content)); |
463 my $time_base = time(); | 472 my $time_base = time(); |
464 | 473 |
465 #print $res->decoded_content; die("\n"); | 474 print $res->decoded_content if opt_chk_bool("dump"); |
466 | 475 |
467 if (defined($xml->{"wfs:member"}{"omso:GridSeriesObservation"})) | 476 if (defined($xml->{"wfs:member"}{"omso:GridSeriesObservation"})) |
468 { | 477 { |
469 my $fdata = $xml->{"wfs:member"}{"omso:GridSeriesObservation"}; | 478 my $fdata = $xml->{"wfs:member"}{"omso:GridSeriesObservation"}; |
470 my $fshit = $fdata->{"om:result"}{"gmlcov:MultiPointCoverage"}; | 479 my $fshit = $fdata->{"om:result"}{"gmlcov:MultiPointCoverage"}; |