changeset 324:19c64798de91

weather: Add some better optional debugging.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 21 May 2015 10:00:29 +0300
parents 9380535b8f12
children fe12434d6cbd
files fetch_weather.pl
diffstat 1 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Mon May 18 13:44:08 2015 +0300
+++ b/fetch_weather.pl	Thu May 21 10:00:29 2015 +0300
@@ -344,6 +344,19 @@
 }
 
 
+sub opt_get_int($)
+{
+  if (defined($settings{$_[0]}))
+  {
+    return int($settings{$_[0]});
+  }
+  else
+  {
+    return -1;
+  }
+}
+
+
 sub opt_get($)
 {
   if (defined($settings{$_[0]}))
@@ -419,8 +432,9 @@
 {
   for (my $i = 1; $i <= 22; $i++)
   {
-    my $qurl = "http://alk.tiehallinto.fi/alk/tiesaa/tiesaa_maak_".$i.".html";
-    my $res = fetch_http($qurl);
+    my $uri = "http://alk.tiehallinto.fi/alk/tiesaa/tiesaa_maak_".$i.".html";
+    print STDERR "Fetching ".$uri." ...\n" if (opt_get_int("debug") > 1);
+    my $res = fetch_http($uri);
     if ($res->code >= 200 && $res->code <= 201)
     {
       my $data = $res->decoded_content;
@@ -446,10 +460,12 @@
       my $otree = parse_html($data);
       if (!defined($otree))
       {
-        print STDERR "ERROR: Failed to parse file '".$qurl."'.\n";
+        print STDERR "ERROR: Failed to parse file '".$uri."'.\n";
         next;
       }
 
+      print STDERR "Parsed : ".$uri." as:\n".Dumper($otree)."\n--\n" if (opt_get_int("debug") > 2);
+
       # Find our desired element nodes
       my $odata = fnodea(fnodep($otree, "body"), "div", "class=elementc");
       my $oupdate = fnodep($odata, "p");
@@ -481,7 +497,13 @@
         }
       }
     }
+    else
+    {
+      print STDERR "Failed to fetch ".$uri." (\n" if (opt_get_int("debug") > 0);
+    }
   }
+
+  print STDERR "Tiehallinto data blob:\n".Dumper($weatherdata)."\n--\n" if (opt_get_int("debug") > 1);
 }
 
 
@@ -500,7 +522,7 @@
     "&starttime=".format_time_gmt(time() - 10*60)."&endtime=".format_time_gmt(time()).
     "&parameters=".join(",", @fmitems)."&maxlocations=100&bbox=19,59,32,75";
 
-  print STDERR "FMI URI: ".$uri."\n" if opt_chk_bool("debug");
+  print STDERR "FMI URI: ".$uri."\n" if (opt_get_int("debug") > 0);
 
   my $res = fetch_http($uri);
   if ($res->code >= 200 && $res->code <= 201)