2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 13:26:02 +00:00

98_rssFeed: new attribute to generate readings containing ticker data

git-svn-id: https://svn.fhem.de/fhem/trunk@11302 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
svnbenni 2016-04-24 15:46:57 +00:00
parent 61926851bc
commit bdb936e4f3
2 changed files with 73 additions and 1 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: 98_rssFeed: creating some readings containing ticker data.
This can be enabled via new attribute rfDisplayTickerReadings.
- change: FB_CALLLIST: delete also corresponding readings if a call gets - change: FB_CALLLIST: delete also corresponding readings if a call gets
deleted deleted
- feature: 49_SSCam: Attribute "disable" to deactivate the module added - feature: 49_SSCam: Attribute "disable" to deactivate the module added

View File

@ -40,6 +40,10 @@ my $nb_indexlength=length($maximum_max_lines);
my $rdHeadlines='.headlines'; my $rdHeadlines='.headlines';
my $tickerReadingsPrefix='ticker';
my $rdToastTicker=$tickerReadingsPrefix.'Toast';
my $rdMarqueeTicker=$tickerReadingsPrefix.'Marquee';
my $defaultReadings="title,description,pubDate"; my $defaultReadings="title,description,pubDate";
my $allReadings=$defaultReadings.",link,buildDate,imageTitle,imageURL,encodedContent"; my $allReadings=$defaultReadings.",link,buildDate,imageTitle,imageURL,encodedContent";
@ -93,6 +97,14 @@ sub rssFeed_NotifyFn($$)
readingsSingleUpdate($hash,'state','defined',1); readingsSingleUpdate($hash,'state','defined',1);
} }
} elsif($event =~/ATTR $name rfDisplayTickerReadings/) {
rssFeed_Log3 $name,4,"$name rfDisplayTickerReadings changed";
if(!AttrVal($name,'rfDisplayTickerReadings',undef)) {
fhem("deletereading $name $tickerReadingsPrefix.*",1);
} else {
readingsSingleUpdate($hash,$rdToastTicker,'waiting for next update...',1);
readingsSingleUpdate($hash,$rdMarqueeTicker,'waiting for next update...',1);
}
} elsif($event eq 'INITIALIZED') { } elsif($event eq 'INITIALIZED') {
if(IsDisabled($name)) { if(IsDisabled($name)) {
rssFeed_update($hash); rssFeed_update($hash);
@ -171,6 +183,7 @@ rssFeed_Initialize($)
. "rfCustomTextPrepFn " #optional preparation of Text readings before they_re set (funtion) . "rfCustomTextPrepFn " #optional preparation of Text readings before they_re set (funtion)
. "rfReadings:multiple-strict,".$allReadings." " #readings to fill (comma separated list) . "rfReadings:multiple-strict,".$allReadings." " #readings to fill (comma separated list)
. "rfDisabledText " . "rfDisabledText "
. "rfDisplayTickerReadings:1,0 "
#. "rfLatin1ToUtf8:1,0" #optional encoding using latin1ToUtf8 for readings (TEST ONLY) #. "rfLatin1ToUtf8:1,0" #optional encoding using latin1ToUtf8 for readings (TEST ONLY)
. $readingFnAttributes; #default FHEM FnAttributes -> see commandref. . $readingFnAttributes; #default FHEM FnAttributes -> see commandref.
} }
@ -429,7 +442,7 @@ rssFeed_update(@)
} }
} }
my ($i,$nachrichten,$response,@ticker,$ua,$url,$xml); my ($i,$nachrichten,$response,@ticker,@mticker,$ua,$url,$xml);
$i = 0; $i = 0;
@ -550,6 +563,7 @@ rssFeed_update(@)
my $h = $tt_start.$cline.$tt_end; my $h = $tt_start.$cline.$tt_end;
last unless $h; last unless $h;
push (@ticker,$h); push (@ticker,$h);
push (@mticker,$cline);
#Index for numbering each news-block #Index for numbering each news-block
my $ndx=sprintf('%0'.$nb_indexlength.'s',$i); my $ndx=sprintf('%0'.$nb_indexlength.'s',$i);
@ -598,6 +612,18 @@ rssFeed_update(@)
my $tickerHeadlines=join("\n", @ticker); my $tickerHeadlines=join("\n", @ticker);
readingsSingleUpdate($dhash,$rdHeadlines, $tickerHeadlines,0); readingsSingleUpdate($dhash,$rdHeadlines, $tickerHeadlines,0);
if(AttrVal($name,"rfDisplayTickerReadings",undef)) {
readingsSingleUpdate($dhash,$rdToastTicker,$tickerHeadlines,1);
my $mTickerLine=join(" $ttt ", @mticker);
readingsSingleUpdate($dhash,$rdMarqueeTicker,$mTickerLine,1);
} else {
fhem("deletereading $name $tickerReadingsPrefix.*",1);
}
return; return;
} }
@ -689,6 +715,8 @@ return;
<br/> <br/>
Result: <code>+++ This is a sample headline +++</code> Result: <code>+++ This is a sample headline +++</code>
<br/> <br/>
These characters are also used for "marquee"-ticker data.
<br>
</li> </li>
<li><a name="rfMaxLines">rfMaxLines</a><br/> <li><a name="rfMaxLines">rfMaxLines</a><br/>
Defines the maximum number of news items that will be extracted from the Defines the maximum number of news items that will be extracted from the
@ -698,6 +726,11 @@ return;
Example: <code>attr &lt;name&gt; rfMaxLines 15</code> Example: <code>attr &lt;name&gt; rfMaxLines 15</code>
<br/> <br/>
</li> </li>
<li><a name="rfDisplayTickerReadings">rfDisplayTickerReadings</a><br/>
If this attribute is set then there will be two additional readings
containing the ticker data for "toast"-Tickers (same as rssFeedGetTicker())
and one containing the ticker data for "marquee"-tickers on a single line.
</li>
<li><a name="rfEncode">rfEncode</a><br/> <li><a name="rfEncode">rfEncode</a><br/>
Defines an encoding which will be used for any text extracted from the Defines an encoding which will be used for any text extracted from the
feed that will be applied before setting the readings. Therefore the feed that will be applied before setting the readings. Therefore the
@ -847,6 +880,20 @@ sub rssFeedPrep($$)
This readings contains the number of new items that were extracted This readings contains the number of new items that were extracted
in the last update of the feed data. in the last update of the feed data.
</li> </li>
<li>
<code>tickerToast</code><br/>
This reading contains the same data that is returned by the rssFeedGetTicker()
funciton (if attribute rfDisplayTickerReadings is set)
<br>
Example: <code>+++ Headline 1 +++ \n +++ Headline 2 +++ \n +++ Headline 3 +++ </code>
</li>
<li>
<code>tickerMarquee</code><br/>
This reading contains the ticker data on a single line for "marquee" style
tickers (if attribute rfDisplayTickerReadings is set)
<br>
Example: <code>Headline 1 +++ Hadline 2 +++ Headline 3 +++</code>
</li>
<li><code>gzippedFeed</code><br/> <li><code>gzippedFeed</code><br/>
Sometimes RSS-Feed data is delivered gzipped. This is automatically Sometimes RSS-Feed data is delivered gzipped. This is automatically
recognized by the module. So if the received data was originally recognized by the module. So if the received data was originally
@ -947,6 +994,8 @@ sub rssFeedPrep($$)
<br> <br>
Ergebnis: <code>+++ Dies ist eine Beispiel-Schlagzeile +++</code> Ergebnis: <code>+++ Dies ist eine Beispiel-Schlagzeile +++</code>
<br> <br>
Diese Zeichenkette wird auch als Trenner für die Marquee-Ticker-Daten verwendet.
<br>
</li> </li>
<li><a name="rfMaxLines">rfMaxLines</a><br> <li><a name="rfMaxLines">rfMaxLines</a><br>
Bestimmt, wieviele Schlagzeilen maximal aus dem Feed extrahiert werden sollen.<br> Bestimmt, wieviele Schlagzeilen maximal aus dem Feed extrahiert werden sollen.<br>
@ -956,6 +1005,13 @@ sub rssFeedPrep($$)
Beispiel: <code>attr &lt;name&gt; rfMaxLines 15</code> Beispiel: <code>attr &lt;name&gt; rfMaxLines 15</code>
<br> <br>
</li> </li>
<li><a name="rfDisplayTickerReadings">rfDisplayTickerReadings</a><br/>
Wenn dieses Attribut gesetzt ist werden 2 zus&auml;tzliche Readings erzeugt, die
die Tickerdaten einmal f&uuml;r s.g. "Toast"-Ticker (der Inhalt ist der selbe,
wie die Ausgabe von rssFeedGetTicker()) und einmal f&uuml;r s.g. "Marquee"-Ticker, also
in einer einzigen Zeile.
<br>
</li>
<li><a name="rfEncode">rfEncode</a><br> <li><a name="rfEncode">rfEncode</a><br>
Hier kann eine Encoding-Methode (Bspw. utf8) angegeben werden. Hier kann eine Encoding-Methode (Bspw. utf8) angegeben werden.
Die Texte die aus dem Feed extrahiert werden (title, descripton, ...) Die Texte die aus dem Feed extrahiert werden (title, descripton, ...)
@ -1106,6 +1162,20 @@ sub rssFeedPrep($$)
Dieses Reading gibt an, wie viele Schlagzeilen tats&auml;chlich beim letzten Dieses Reading gibt an, wie viele Schlagzeilen tats&auml;chlich beim letzten
update aus dem Nachrichten-Feed extrahiert wurden. update aus dem Nachrichten-Feed extrahiert wurden.
</li> </li>
<li>
<code>tickerToast</code><br/>
Dieses Reading ent&auml; die selben Daten, wie sie von der rssFeedGetTicker()
Funktion zur&uuml;ckgeliefert werden (if attribute rfDisplayTickerReadings is set)
<br>
Beispiel: <code>+++ Headline 1 +++ \n +++ Headline 2 +++ \n +++ Headline 3 +++ </code>
</li>
<li>
<code>tickerMarquee</code><br/>
Dieses Reading enth&auml;lt die Tickerdaten f&uuml;r "marquee"-artige Ticker,
also auf einer Zeile (if attribute rfDisplayTickerReadings is set)
<br>
Beispiel: <code>Headline 1 +++ Hadline 2 +++ Headline 3 +++</code>
</li>
<li><code>gzippedFeed</code><br> <li><code>gzippedFeed</code><br>
Manche Feeds werden in gezippter (gzip) Form ausgeliefert. Das wird vom Manche Feeds werden in gezippter (gzip) Form ausgeliefert. Das wird vom
Modul automatisch erkannt und die Daten im Bedarfsfall dekomprimiert. Modul automatisch erkannt und die Daten im Bedarfsfall dekomprimiert.