mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-30 13:09:34 +00:00
Add possibility to display item description. #157
This commit is contained in:
parent
a64699d064
commit
af2f469b84
@ -44,8 +44,15 @@ The following properties can be configured:
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>showPublishDate</code></td>
|
<td><code>showPublishDate</code></td>
|
||||||
<td>Display the publish date of an headline.<br>
|
<td>Display the publish date of an headline.<br>
|
||||||
|
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
|
||||||
<br><b>Default value:</b> <code>true</code>
|
<br><b>Default value:</b> <code>true</code>
|
||||||
<br><b>Default value:</b> <code>true</code> or <code>false</code>
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>showDescription</code></td>
|
||||||
|
<td>Display the description of an item.<br>
|
||||||
|
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
|
||||||
|
<br><b>Default value:</b> <code>false</code>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@ -60,7 +67,7 @@ The following properties can be configured:
|
|||||||
<td><code>updateInterval</code></td>
|
<td><code>updateInterval</code></td>
|
||||||
<td>How often do you want to display a new headline? (Milliseconds)<br>
|
<td>How often do you want to display a new headline? (Milliseconds)<br>
|
||||||
<br><b>Possible values:</b><code>1000</code> - <code>60000</code>
|
<br><b>Possible values:</b><code>1000</code> - <code>60000</code>
|
||||||
<br><b>Default value:</b> <code>7500</code> (7.5 seconds)
|
<br><b>Default value:</b> <code>10000</code> (10 seconds)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var NewsFetcher = require("./newsfetcher.js");
|
var FeedMe = require("feedme");
|
||||||
|
var request = require("request");
|
||||||
|
var iconv = require("iconv-lite");
|
||||||
|
|
||||||
/* Fetcher
|
/* Fetcher
|
||||||
* Responsible for requesting an update on the set interval and broadcasting the data.
|
* Responsible for requesting an update on the set interval and broadcasting the data.
|
||||||
@ -16,7 +18,6 @@ var NewsFetcher = require("./newsfetcher.js");
|
|||||||
|
|
||||||
var Fetcher = function(url, reloadInterval, encoding) {
|
var Fetcher = function(url, reloadInterval, encoding) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var newsFetcher = new NewsFetcher();
|
|
||||||
if (reloadInterval < 1000) {
|
if (reloadInterval < 1000) {
|
||||||
reloadInterval = 1000;
|
reloadInterval = 1000;
|
||||||
}
|
}
|
||||||
@ -30,21 +31,40 @@ var Fetcher = function(url, reloadInterval, encoding) {
|
|||||||
/* private methods */
|
/* private methods */
|
||||||
|
|
||||||
/* fetchNews()
|
/* fetchNews()
|
||||||
* Request the new items from the newsFetcher.
|
* Request the new items.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var fetchNews = function() {
|
var fetchNews = function() {
|
||||||
//console.log('Fetch news.');
|
|
||||||
clearTimeout(reloadTimer);
|
clearTimeout(reloadTimer);
|
||||||
reloadTimer = null;
|
reloadTimer = null;
|
||||||
newsFetcher.fetchNews(url, function(fetchedItems) {
|
items = [];
|
||||||
items = fetchedItems;
|
|
||||||
|
var parser = new FeedMe();
|
||||||
|
|
||||||
|
parser.on("item", function(item) {
|
||||||
|
var description = item.description || '';
|
||||||
|
var regex = /(<([^>]+)>)/ig;
|
||||||
|
description = description.replace(regex, "");
|
||||||
|
|
||||||
|
items.push({
|
||||||
|
title: item.title,
|
||||||
|
description: description,
|
||||||
|
pubdate: item.pubdate,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.on("end", function() {
|
||||||
self.broadcastItems();
|
self.broadcastItems();
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
}, function(error) {
|
});
|
||||||
|
|
||||||
|
parser.on("error", function(error) {
|
||||||
fetchFailedCallback(self, error);
|
fetchFailedCallback(self, error);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
}, encoding);
|
});
|
||||||
|
|
||||||
|
request({uri: url, encoding: null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* scheduleTimer()
|
/* scheduleTimer()
|
||||||
|
@ -13,8 +13,9 @@ Module.register("newsfeed",{
|
|||||||
defaults: {
|
defaults: {
|
||||||
feedUrl: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
|
feedUrl: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
|
||||||
showPublishDate: true,
|
showPublishDate: true,
|
||||||
|
showDescription: false,
|
||||||
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
||||||
updateInterval: 7.5 * 1000,
|
updateInterval: 10 * 1000,
|
||||||
animationSpeed: 2.5 * 1000,
|
animationSpeed: 2.5 * 1000,
|
||||||
encoding: "UTF-8" //ISO-8859-1
|
encoding: "UTF-8" //ISO-8859-1
|
||||||
},
|
},
|
||||||
@ -83,6 +84,13 @@ Module.register("newsfeed",{
|
|||||||
title.innerHTML = this.newsItems[this.activeItem].title;
|
title.innerHTML = this.newsItems[this.activeItem].title;
|
||||||
wrapper.appendChild(title);
|
wrapper.appendChild(title);
|
||||||
|
|
||||||
|
if (this.config.showDescription) {
|
||||||
|
var description = document.createElement("div");
|
||||||
|
description.className = "small light";
|
||||||
|
description.innerHTML = this.newsItems[this.activeItem].description;
|
||||||
|
wrapper.appendChild(description);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wrapper.innerHTML = "Loading news ...";
|
wrapper.innerHTML = "Loading news ...";
|
||||||
wrapper.className = "small dimmed";
|
wrapper.className = "small dimmed";
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
/* Magic Mirror
|
|
||||||
* NewsFetcher
|
|
||||||
*
|
|
||||||
* By Michael Teeuw http://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var FeedMe = require("feedme");
|
|
||||||
var request = require("request");
|
|
||||||
var iconv = require("iconv-lite");
|
|
||||||
|
|
||||||
var NewsFetcher = function() {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
self.successCallback = function() {};
|
|
||||||
self.errorCallback = function() {};
|
|
||||||
|
|
||||||
self.items = [];
|
|
||||||
|
|
||||||
/* fetchNews()
|
|
||||||
* Fetch the new news items.
|
|
||||||
*
|
|
||||||
* attribute url string - The url to fetch.
|
|
||||||
* attribute success function(items) - Callback on succes.
|
|
||||||
* attribute error function(error) - Callback on error.
|
|
||||||
*/
|
|
||||||
self.fetchNews = function(url, success, error, encoding) {
|
|
||||||
self.successCallback = success;
|
|
||||||
self.errorCallback = error;
|
|
||||||
|
|
||||||
var parser = new FeedMe();
|
|
||||||
|
|
||||||
parser.on("item", function(item) {
|
|
||||||
self.items.push({
|
|
||||||
title: item.title,
|
|
||||||
pubdate: item.pubdate,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
parser.on("end", function(item) {
|
|
||||||
self.successCallback(self.items);
|
|
||||||
});
|
|
||||||
|
|
||||||
parser.on("error", function(error) {
|
|
||||||
self.errorCallback(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
request({uri: url, encoding: null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = NewsFetcher;
|
|
Loading…
x
Reference in New Issue
Block a user