changeset 162:4f8a163b2bc1

Work on the backend weather data fetching.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 02 Jun 2014 15:56:01 +0300
parents 2c9db9a29429
children bee5cd89d41c
files fetch_weather.pl
diffstat 1 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Mon Jun 02 15:53:53 2014 +0300
+++ b/fetch_weather.pl	Mon Jun 02 15:56:01 2014 +0300
@@ -7,6 +7,14 @@
 use Date::Parse;
 use Data::Dumper;
 
+###
+### Settings
+###
+my $opt_outfile = "/home/niinuska/bot/weather.data";
+
+###
+### Helper functions
+###
 sub str_trim($)
 {
   my $str = $_[0];
@@ -170,20 +178,13 @@
 
 sub parse_timestamp($$)
 {
-  return $_[1] + str2time($_[0]) - time();
+  return str2time($_[0]) - str2time("00:00") + $_[1];
 }
 
 
 ###
 ### Main program begins
 ###
-die(
-"Weather Fetch v0.1 by ccr/TNSP <ccr\@tnsp.org>\n".
-"Usage: $0 <output_data_file> <fmi_api_key>\n"
-) unless scalar(@ARGV) >= 2;
-
-my $opt_outfile = shift;
-my $opt_api_key = shift;
 my $weatherdata = {};
 
 ### Fetch tiehallinto data
@@ -217,7 +218,7 @@
     # Find our desired element nodes
     my $odata = fnodea(fnode($otree, "body"), "div", "class=elementc");
     my $oupdate = fnode($odata, "p");
-    my $time_base = time();
+    my $time_base = str2time("00:00");
     if ($oupdate) {
       my $tmp = $oupdate->{"nodes"}[0]{"text"};
       if ($tmp =~ /:\s+(\d\d\.\d\d\.\d\d\d\d)\s+(\d\d:\d\d)/) {
@@ -238,7 +239,6 @@
         get_node($fdata, "text", 5),
       ];
     }
-    print STDERR ".";
   }
 }