2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

FRITZBOX: umlaute in email body

git-svn-id: https://svn.fhem.de/fhem/trunk@8450 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
tpoitzsch 2015-04-18 11:52:07 +00:00
parent 6dd36c396d
commit 222c1e271f
2 changed files with 60 additions and 19 deletions

View File

@ -33,6 +33,8 @@
# parser for the weather data # parser for the weather data
package MyProplantaParser; package MyProplantaParser;
use base qw(HTML::Parser); use base qw(HTML::Parser);
use Time::HiRes qw(usleep nanosleep);
our @texte = (); our @texte = ();
my $lookupTag = "span|b"; my $lookupTag = "span|b";
my $curTag = ""; my $curTag = "";
@ -163,6 +165,8 @@ sub text
my ( $self, $text ) = @_; my ( $self, $text ) = @_;
my $found = 0; my $found = 0;
my $readingName; my $readingName;
# Wait 1ms to reduce CPU load and hence blocking of FHEM by it (workaround until a better solution is available)
usleep (1000);
if ( $curTag =~ $lookupTag ) if ( $curTag =~ $lookupTag )
{ {
$curTextPos++; $curTextPos++;
@ -391,6 +395,7 @@ my $missingModul;
eval "use LWP::UserAgent;1" or $missingModul .= "LWP::UserAgent "; eval "use LWP::UserAgent;1" or $missingModul .= "LWP::UserAgent ";
eval "use HTTP::Request;1" or $missingModul .= "HTTP::Request "; eval "use HTTP::Request;1" or $missingModul .= "HTTP::Request ";
eval "use HTML::Parser;1" or $missingModul .= "HTML::Parser "; eval "use HTML::Parser;1" or $missingModul .= "HTML::Parser ";
eval "use MIME::Base64;1" or $missingModul .= "MIME::Base64 ";
require 'Blocking.pm'; require 'Blocking.pm';
require 'HttpUtils.pm'; require 'HttpUtils.pm';
@ -469,8 +474,8 @@ sub PROPLANTA_Define($$)
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
#Get first data after 12 seconds #Get first data after 32 seconds
InternalTimer( gettimeofday() + 12, "PROPLANTA_Start", $hash, 0 ); InternalTimer( gettimeofday() + 32, "PROPLANTA_Start", $hash, 0 );
return undef; return undef;
} }
@ -557,11 +562,11 @@ sub PROPLANTA_Start($)
$hash->{INTERVAL} = AttrVal( $name, "INTERVAL", $hash->{INTERVAL} ); $hash->{INTERVAL} = AttrVal( $name, "INTERVAL", $hash->{INTERVAL} );
if(!$hash->{fhem}{LOCAL} && $hash->{INTERVAL} > 0) { if($hash->{INTERVAL} > 0) {
# set up timer if automatically call # reset timer if interval is defined
RemoveInternalTimer( $hash ); RemoveInternalTimer( $hash );
InternalTimer(gettimeofday() + $hash->{INTERVAL}, "PROPLANTA_Start", $hash, 1 ); InternalTimer(gettimeofday() + $hash->{INTERVAL}, "PROPLANTA_Start", $hash, 1 );
return undef if( AttrVal($name, "disable", 0 ) == 1 ); return undef if AttrVal($name, "disable", 0 ) == 1 && !$hash->{fhem}{LOCAL};
} }
if ( AttrVal( $name, 'URL', '') eq '' && not defined( $hash->{URL} ) ) if ( AttrVal( $name, 'URL', '') eq '' && not defined( $hash->{URL} ) )
@ -570,6 +575,16 @@ sub PROPLANTA_Start($)
return; return;
} }
# "Set update"-action will kill a running update child process
if (defined ($hash->{helper}{RUNNING_PID}) && $hash->{fhem}{LOCAL})
{
BlockingKill($hash->{helper}{RUNNING_PID});
delete( $hash->{helper}{RUNNING_PID} );
PROPLANTA_Log $hash, 4, "Killing old forked process";
}
unless (defined ($hash->{helper}{RUNNING_PID}))
{
$hash->{helper}{RUNNING_PID} = $hash->{helper}{RUNNING_PID} =
BlockingCall( BlockingCall(
"PROPLANTA_Run", # callback worker task "PROPLANTA_Run", # callback worker task
@ -578,11 +593,18 @@ sub PROPLANTA_Start($)
120, # timeout seconds 120, # timeout seconds
"PROPLANTA_Aborted", # callback for abortion "PROPLANTA_Aborted", # callback for abortion
$hash ); # parameter for abortion $hash ); # parameter for abortion
PROPLANTA_Log $hash, 4, "Start forked process to capture html";
}
else
{
PROPLANTA_Log $hash, 1, "Could not start forked process, old process still running";
}
} }
##################################### #####################################
sub PROPLANTA_Run($) sub PROPLANTA_Run($)
{ {
setpriority( 0, 0, 10);
my ($name) = @_; my ($name) = @_;
my $ptext=$name; my $ptext=$name;
my $URL; my $URL;
@ -656,6 +678,7 @@ sub PROPLANTA_Run($)
return $ptext; return $ptext;
} }
##################################### #####################################
# asyncronous callback by blocking # asyncronous callback by blocking
sub PROPLANTA_Done($) sub PROPLANTA_Done($)
@ -668,9 +691,12 @@ sub PROPLANTA_Done($)
my $hash = $defs{$name}; my $hash = $defs{$name};
return unless ( defined($hash->{NAME}) ); return unless ( defined($hash->{NAME}) );
PROPLANTA_Log $hash, 4, "Forked process successfully finished";
# delete the marker for RUNNING_PID process # delete the marker for RUNNING_PID process
delete( $hash->{helper}{RUNNING_PID} ); delete( $hash->{helper}{RUNNING_PID} );
# Wetterdaten speichern # Wetterdaten speichern
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
@ -718,11 +744,13 @@ sub PROPLANTA_Done($)
} }
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
} }
##################################### #####################################
sub PROPLANTA_Aborted($) sub PROPLANTA_Aborted($)
{ {
my ($hash) = @_; my ($hash) = @_;
delete( $hash->{helper}{RUNNING_PID} ); delete( $hash->{helper}{RUNNING_PID} );
PROPLANTA_Log $hash, 4, "Forked process timed out";
} }
##### noch nicht fertig ########### ##### noch nicht fertig ###########
@ -789,6 +817,8 @@ PROPLANTA_Html($)
<br> <br>
The website provides a forecast for 12 days, for the first 7 days in a 3-hours-interval. The website provides a forecast for 12 days, for the first 7 days in a 3-hours-interval.
<br> <br>
This modul causes a high CPU load. It is recommended to reduce the number of captured forecast days.
<br>
It uses the perl moduls HTTP::Request, LWP::UserAgent and HTML::Parse. It uses the perl moduls HTTP::Request, LWP::UserAgent and HTML::Parse.
<br/><br/> <br/><br/>
<a name="PROPLANTAdefine"></a> <a name="PROPLANTAdefine"></a>
@ -894,6 +924,8 @@ PROPLANTA_Html($)
<br/> <br/>
Es stellt eine Vorhersage f&uuml;r 12 Tage zur Verf&uuml;gung - w&auml;hrend der ersten 7 Tage im 3-Stunden-Intervall. Es stellt eine Vorhersage f&uuml;r 12 Tage zur Verf&uuml;gung - w&auml;hrend der ersten 7 Tage im 3-Stunden-Intervall.
<br> <br>
Dieses Modul erzeugt eine hohe CPU-Last. Es wird deshalb empfohlen, die auszulesenden Vorhersagetage zu reduzieren.
<br>
<i>Es nutzt die Perl-Module HTTP::Request, LWP::UserAgent und HTML::Parse</i>. <i>Es nutzt die Perl-Module HTTP::Request, LWP::UserAgent und HTML::Parse</i>.
<br/><br/> <br/><br/>
<b>Define</b> <b>Define</b>

View File

@ -2383,6 +2383,15 @@ sub FRITZBOX_SendMail($@)
{ {
chop $field{body}; chop $field{body};
$field{body} =~ s/"/\\"/g; $field{body} =~ s/"/\\"/g;
# change none ASCII chars in octal code for ISO-8859-1 (acc. http://www.pjb.com.au/comp/diacritics.html)
$field{body} =~ s/Ä|Ä/\\304/g;
$field{body} =~ s/Ö|Ö/\\326/g;
$field{body} =~ s/Ü|Ãœ/\\334/g;
$field{body} =~ s/ß|ß/\\337/g;
$field{body} =~ s/ä|ä/\\344/g;
$field{body} =~ s/ö|ö/\\366/g;
$field{body} =~ s/ü|ü/\\374/g;
push @cmdArray, '/bin/echo -e "'.$field{body}.'" >/var/tmp/fhem_nachricht.txt'; push @cmdArray, '/bin/echo -e "'.$field{body}.'" >/var/tmp/fhem_nachricht.txt';
$cmd .= " -i '/var/tmp/fhem_nachricht.txt'"; $cmd .= " -i '/var/tmp/fhem_nachricht.txt'";
} }
@ -2405,8 +2414,8 @@ sub FRITZBOX_SendMail($@)
return undef; return undef;
} }
sub ########################################## ##########################################
FRITZBOX_StartRadio($@) sub FRITZBOX_StartRadio($@)
{ {
my ($hash, @val) = @_; my ($hash, @val) = @_;
my @cmdArray; my @cmdArray;