mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 16:59:18 +00:00
55_bshGezeiten.pm:
git-svn-id: https://svn.fhem.de/fhem/trunk@15622 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ccaee28b71
commit
0f0a1716d9
91
fhem/contrib/betateilchen/55_bshGezeiten.pm
Normal file
91
fhem/contrib/betateilchen/55_bshGezeiten.pm
Normal file
@ -0,0 +1,91 @@
|
||||
##############################################
|
||||
# $Id$
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use HTML::TreeBuilder::XPath;
|
||||
|
||||
sub bshGezeiten_Initialize($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
# $hash->{SetFn} = "bshG_Set";
|
||||
$hash->{DefFn} = "bshG_Define";
|
||||
$hash->{UndefFn} = "bshG_Undefine";
|
||||
$hash->{AttrList} = "bsh_skipOutdated:1,0 " .
|
||||
$readingFnAttributes;
|
||||
}
|
||||
|
||||
###################################
|
||||
|
||||
sub bshG_Define($$) {
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "Wrong syntax: use define <name> bshGezeiten <location>" if(int(@a) != 3);
|
||||
|
||||
$hash->{'.url'} = "http://mobile.bsh.de/cgi-bin/gezeiten/was_mobil.pl?ort=__LOC__&zone=Gesetzliche+Zeit&niveau=KN";
|
||||
$hash->{'.url'} =~ s/__LOC__/$a[2]/;
|
||||
_bsh_pegel($hash);
|
||||
readingsSingleUpdate($hash, 'state', 'initialized', 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub bshG_Undefine($) {
|
||||
my ($hash) = @_;
|
||||
RemoveInternalTimer($hash);
|
||||
return;
|
||||
}
|
||||
|
||||
sub _bsh_pegel($) {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
# my $next = computeAlignTime("01:00", "00:01");
|
||||
# $hash->{TRIGGERTIME} = $next;
|
||||
# $hash->{TRIGGERTIME_FMT} = FmtDateTime($next);
|
||||
InternalTimer(gettimeofday()+3600, "_bsh_pegel", $hash, 0);
|
||||
HttpUtils_NonblockingGet({
|
||||
hash => $hash,
|
||||
timeout => 5,
|
||||
url => $hash->{'.url'},
|
||||
callback => \&_bsh_pegel_cb,
|
||||
})
|
||||
}
|
||||
|
||||
sub _bsh_pegel_cb($){
|
||||
my ($param, $err, $content) = @_;
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $tree= HTML::TreeBuilder::XPath->new;
|
||||
$tree->parse($content);
|
||||
my @ort = $tree->findvalues(q{//strong});
|
||||
my (undef,undef,$ort) = split(/ /,$ort[1],3);
|
||||
$ort = latin1ToUtf8($ort);
|
||||
my @values = $tree->findvalues(q{//table//tr});
|
||||
my $counter = 0;
|
||||
my $year = (split(/ /,localtime(time)))[4];
|
||||
readingsBeginUpdate($hash);
|
||||
foreach my $v (@values){
|
||||
next if(length($v) < 2);
|
||||
#Sa16.12.HW03:09 4.0<EFBFBD>m
|
||||
my $d = substr($v,2,6);
|
||||
my $w = substr($v,8,2);
|
||||
my $t = substr($v,10,5);
|
||||
my $h = substr($v,15,4);
|
||||
if (AttrVal($name,'bsh_skipOutdated',1)) {
|
||||
my ($day1,$month1) = split(/\./,$d);
|
||||
my ($hour1,$min1) = split(/:/,$t);
|
||||
my $x = time_str2num "$year-$month1-$day1 $hour1:$min1:00";
|
||||
next if time > $x;
|
||||
}
|
||||
$counter++;
|
||||
readingsBulkUpdate($hash, sprintf('Meldung.%02s',$counter), "$w $d $t $h");
|
||||
last if ($counter == 8);
|
||||
}
|
||||
readingsBulkUpdate($hash,'Pegelname',$ort);
|
||||
readingsBulkUpdate($hash,'state','active');
|
||||
readingsEndUpdate($hash,1);
|
||||
}
|
||||
|
||||
1;
|
Loading…
x
Reference in New Issue
Block a user