changeset 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 c95c0eb0a10f
children 204699e84dee
files fetch_weather.pl
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Sun May 23 13:25:48 2021 +0300
+++ b/fetch_weather.pl	Sun May 23 13:26:15 2021 +0300
@@ -39,6 +39,7 @@
 my %settings = (
   "force_update" => 0,
   "debug" => 0,
+  "dump" => 0,
   "opt_fmi" => 0,
   "opt_tiehallinto" => 0,
   "purge_threshold" => 60,
@@ -276,6 +277,10 @@
   {
     $settings{"debug"} = 1;
   }
+  elsif ($arg eq "-dump")
+  {
+    $settings{"dump"} = 1;
+  }
   else
   {
     die("Configuration file already specified!\n") if defined($opt_cfgfile);
@@ -291,6 +296,7 @@
     "\n".
     " -force      : Force updating of all data\n".
     " -debug      : Enable debug\n".
+    " -dump       : Dump received raw data\n".
     "\n"
   );
 }
@@ -337,7 +343,7 @@
     my $json_str = force_decode_utf8($res->decoded_content);
     my $data = JSON->new->decode($json_str);
 
-#print $json_str."\n"; die("\n");
+    print $json_str if opt_chk_bool("dump");
 
     if (!defined($data->{"dataUpdatedTime"}) || !defined($data->{"weatherStations"}))
     {
@@ -445,7 +451,10 @@
 ###
 if (opt_chk_bool("opt_fmi"))
 {
-  my @fmitems = ("temperature", "humidity", "windspeedms", "winddirection", "totalcloudcover");
+  my @fmitems = (
+    "temperature", "humidity", "windspeedms",
+    "winddirection", "totalcloudcover",
+    );
 
   my $uri = opt_get("fmi_weather_base_url").
     "?request=getFeature".
@@ -462,7 +471,7 @@
     my $xml = XMLin(force_decode_utf8($res->decoded_content));
     my $time_base = time();
 
-#print $res->decoded_content; die("\n");
+    print $res->decoded_content if opt_chk_bool("dump");
 
     if (defined($xml->{"wfs:member"}{"omso:GridSeriesObservation"}))
     {