# HG changeset patch # User Matti Hamalainen # Date 1401713761 -10800 # Node ID 4f8a163b2bc18ef5ade13c038d2a6156e01c0c7c # Parent 2c9db9a29429417b31ca7a8ec8d9aae09af4dbf7 Work on the backend weather data fetching. diff -r 2c9db9a29429 -r 4f8a163b2bc1 fetch_weather.pl --- 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 \n". -"Usage: $0 \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 "."; } }