changeset 328:b3fded816ad8

Merged.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jun 2015 18:51:42 +0300
parents a5282cdc56e6 (current diff) fe12434d6cbd (diff)
children 50d47bdd4425
files
diffstat 1 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Wed Jun 03 18:51:30 2015 +0300
+++ b/fetch_weather.pl	Wed Jun 03 18:51:42 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]}))
@@ -404,7 +417,7 @@
 my $weatherdata = {};
 
 die(
-"Weather Fetch v0.1 by ccr/TNSP <ccr\@tnsp.org>\n".
+"Weather Fetch v0.3 by ccr/TNSP <ccr\@tnsp.org>\n".
 "Usage: $0 <config file>\n"
 ) unless scalar(@ARGV) >= 1;
 
@@ -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)