From b220b12210c81cb7fb9b1f5f5fa9143db33b543b Mon Sep 17 00:00:00 2001 From: tpoitzsch Date: Sun, 9 Nov 2014 18:09:55 +0000 Subject: [PATCH] PROPLANTA: Small fixes git-svn-id: https://svn.fhem.de/fhem/trunk@6933 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/59_PROPLANTA.pm | 122 ++++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 19 deletions(-) diff --git a/fhem/FHEM/59_PROPLANTA.pm b/fhem/FHEM/59_PROPLANTA.pm index ad8ea85db..cf2c30fc3 100644 --- a/fhem/FHEM/59_PROPLANTA.pm +++ b/fhem/FHEM/59_PROPLANTA.pm @@ -42,7 +42,7 @@ my $curCol = 0; my $curTextPos = 0; my $curReadingType = 0; - # 1 = Span Text, 2 = readingName, 3 = Tag-Type + # 1 = span|b Text, 2 = readingName, 3 = Tag-Type # Tag-Types: # 1 = Number Col 3 # 2 = Number Col 2-5 @@ -51,13 +51,15 @@ my $curReadingType = 0; # 5 = Time Col 2-5 # 6 = Time Col 3 # 7 = Image Col 2-5 + # 8 = MinMaxNummer Col 3 my @knownNoneIDs = ( ["Temperatur", "temperature", 1] ,["relative Feuchte", "humidity", 1] ,["Sichtweite", "visibility", 1] ,["Windgeschwindigkeit", "wind", 1] ,["Luftdruck", "pressure", 1] ,["Taupunkt", "dewPoint", 1] - ,["Uhrzeit", "time", 6] + ,["Uhrzeit", "obs_time", 6] + ,["Höhe der", "cloudBase", 8] ); # 1 = Tag-ID, 2 = readingName, 3 = Tag-Type (see above) @@ -121,19 +123,6 @@ my $curReadingType = 0; ,"stark" => 3 ); - my %url_start =( "de" => "http://www.proplanta.de/Wetter/" - , "at" => "http://www.proplanta.de/Agrarwetter-Oesterreich/" - , "ch" => "http://www.proplanta.de/Agrarwetter-Schweiz/" - , "fr" => "http://www.proplanta.de/Agrarwetter-Frankreich/" - , "it" => "http://www.proplanta.de/Agrarwetter-Italien/" - ); - - my %url_end = ( "de" => "-Wetter.html" - , "at" => "/" - , "ch" => "/" - , "fr" => "/" - , "it" => "/" - ); # here HTML::text/start/end are overridden sub text @@ -245,6 +234,24 @@ sub text push( @texte, $readingName."|".$text ); } } + # Tag-Type 8 = MinMaxNumber Col 3 + elsif ($curReadingType == 8) + { + if ( $curCol == 3 ) + { + $readingName = $curReadingName; + if ( $text =~ m/(\d+)\s*-\s*(\d+)/ ) + { + push( @texte, $readingName."Min|".$1 ); + push( @texte, $readingName."Max|".$2 ); + } + else + { + push( @texte, $readingName."Min|-" ); + push( @texte, $readingName."Max|-" ); + } + } + } } } @@ -314,13 +321,28 @@ use warnings; use Data::Dumper; use LWP::UserAgent; use HTTP::Request; +use HTML::Parser; require 'Blocking.pm'; require 'HttpUtils.pm'; use vars qw($readingFnAttributes); use vars qw(%defs); my $MODUL = "PROPLANTA"; -my $modulVersion = "2014-11-06"; +my $modulVersion = '$Id $'; + + my %url_start =( "de" => "http://www.proplanta.de/Wetter/" + , "at" => "http://www.proplanta.de/Agrarwetter-Oesterreich/" + , "ch" => "http://www.proplanta.de/Agrarwetter-Schweiz/" + , "fr" => "http://www.proplanta.de/Agrarwetter-Frankreich/" + , "it" => "http://www.proplanta.de/Agrarwetter-Italien/" + ); + + my %url_end = ( "de" => "-Wetter.html" + , "at" => "/" + , "ch" => "/" + , "fr" => "/" + , "it" => "/" + ); ######################################## @@ -438,8 +460,7 @@ sub PROPLANTA_HtmlAcquire($) my $err_log = ""; my $agent = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 10 ); - my $header = HTTP::Request->new( GET => $URL ); - my $request = HTTP::Request->new( 'GET', $URL, $header ); + my $request = HTTP::Request->new( GET => $URL ); my $response = $agent->request($request); $err_log = "Can't get $URL -- " . $response->status_line unless $response->is_success; @@ -509,11 +530,15 @@ sub PROPLANTA_Run($) } elsif ($response ne "") { + PROPLANTA_Log $hash, 5, "Start HTML parsing"; + +# Can't locate object method "new" via package " my $parser = MyProplantaParser->new; + $parser->report_tags(qw(tr td span b img)); @MyProplantaParser::texte = (); # parsing the complete html-page-response, needs some time - PROPLANTA_Log $hash, 5, "Start HTML parsing"; $parser->parse($response); + PROPLANTA_Log $hash, 4, "Found terms: " . @MyProplantaParser::texte; # pack the results in a single string @@ -523,6 +548,10 @@ sub PROPLANTA_Run($) } PROPLANTA_Log $hash, 4, "Parsed string: " . $ptext; } + else + { + PROPLANTA_Log $hash, 1, "Error. No response string."; + } return $ptext; } ##################################### @@ -577,6 +606,48 @@ sub PROPLANTA_Aborted($) delete( $hash->{helper}{RUNNING_PID} ); } +##### noch nicht fertig ########### +sub ##################################### +PROPLANTA_Html($) +{ + my ($d) = @_; + $d = "" if(!$d); + return "$d is not a PROPLANTA instance
" + if(!$defs{$d} || $defs{$d}{TYPE} ne "PROPLANTA"); + + my $uselocal= 0; #AttrVal($d,"localicons",0); + my $isday; + if ( exists &isday) + { + $isday = isday(); + } + else + { + $isday = 1; #($hour>6 && $hour<19); + } + + my $ret = ""; + $ret .= sprintf '', $defs{$d}{DEF}; + +# $ret .= sprintf('', +# WWOIconIMGTag(ReadingsVal($d, "icon", ""),$uselocal,$isday), +# ReadingsVal($d, "localObsDateTime", ""),ReadingsVal($d, "weatherDesc", ""), +# ReadingsVal($d, "temp_C", ""), ReadingsVal($d, "humidity", ""), +# ReadingsVal($d, "windspeedKmph", ""), ReadingsVal($d, "winddir16Point", ""), +# ReadingsVal($d, "pressure", ""),ReadingsVal($d, "visibility", "")); + + # for(my $i=0; $i<=4; $i++) { + # $ret .= sprintf('', + # WWOIconIMGTag(ReadingsVal($d, "fc${i}_weatherDayIcon", ""),$uselocal,$isday), + # ReadingsVal($d, "fc${i}_date", ""), + # ReadingsVal($d, "fc${i}_weatherDay", ""), + # ReadingsVal($d, "fc${i}_tempMinC", ""), ReadingsVal($d, "fc${i}_tempMaxC", ""), + # } + + $ret .= "
%s
%s%s %s
temp: %s °C, hum %s
wind: %s km/h %s
pressure: %s bar visibility: %s km
%s%s: %s
min %s °C max %s °C
wind: %s km/h %s
precip: %s mm
"; + + return $ret; +} ##################################### 1; @@ -758,6 +829,19 @@ sub PROPLANTA_Aborted($)
  • fc0_weatherDayIcon - Icon Wetterzustand heute tagsüber
  • etc.
  • +
    + Aktuelle Werte +