mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-27 08:22:05 +00:00
Standardize: TO JSCS!
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var NewsFetcher = require('./newsfetcher.js');
|
||||
var NewsFetcher = require("./newsfetcher.js");
|
||||
|
||||
/* Fetcher
|
||||
* Responsible for requesting an update on the set interval and broadcasting the data.
|
||||
|
@@ -7,26 +7,26 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
Module.register('newsfeed',{
|
||||
Module.register("newsfeed",{
|
||||
|
||||
// Default module config.
|
||||
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,
|
||||
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
||||
updateInterval: 7.5 * 1000,
|
||||
animationSpeed: 2.5 * 1000,
|
||||
encoding: 'UTF-8' //ISO-8859-1
|
||||
updateInterval: 7.5 * 1000,
|
||||
animationSpeed: 2.5 * 1000,
|
||||
encoding: "UTF-8" //ISO-8859-1
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
getScripts: function() {
|
||||
return ['moment.js'];
|
||||
return ["moment.js"];
|
||||
},
|
||||
|
||||
// Define start sequence.
|
||||
start: function() {
|
||||
Log.info('Starting module: ' + this.name);
|
||||
Log.info("Starting module: " + this.name);
|
||||
|
||||
// Set locale.
|
||||
moment.locale(config.language);
|
||||
@@ -41,7 +41,7 @@ Module.register('newsfeed',{
|
||||
|
||||
// Override socket notification handler.
|
||||
socketNotificationReceived: function(notification, payload) {
|
||||
if (notification === 'NEWS_ITEMS') {
|
||||
if (notification === "NEWS_ITEMS") {
|
||||
if (payload.url === this.config.feedUrl) {
|
||||
this.newsItems = payload.items;
|
||||
if (!this.loaded) {
|
||||
@@ -73,7 +73,7 @@ Module.register('newsfeed',{
|
||||
if (this.config.showPublishDate) {
|
||||
var timestamp = document.createElement("div");
|
||||
timestamp.className = "light small dimmed";
|
||||
timestamp.innerHTML = this.capitalizeFirstLetter(moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ':');
|
||||
timestamp.innerHTML = this.capitalizeFirstLetter(moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ":");
|
||||
//timestamp.innerHTML = this.config.feedUrl;
|
||||
wrapper.appendChild(timestamp);
|
||||
}
|
||||
@@ -95,8 +95,8 @@ Module.register('newsfeed',{
|
||||
* Requests new data from news proxy.
|
||||
*/
|
||||
fetchNews: function() {
|
||||
Log.log('Add news feed to fetcher: ' + this.config.feedUrl);
|
||||
this.sendSocketNotification('ADD_FEED', {
|
||||
Log.log("Add news feed to fetcher: " + this.config.feedUrl);
|
||||
this.sendSocketNotification("ADD_FEED", {
|
||||
url: this.config.feedUrl,
|
||||
reloadInterval: this.config.reloadInterval,
|
||||
encoding: this.config.encoding
|
||||
@@ -125,6 +125,6 @@ Module.register('newsfeed',{
|
||||
* return string - Capitalized output string.
|
||||
*/
|
||||
capitalizeFirstLetter: function(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
});
|
||||
|
@@ -5,15 +5,15 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var FeedMe = require('feedme');
|
||||
var request = require('request');
|
||||
var iconv = require('iconv-lite');
|
||||
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.successCallback = function() {};
|
||||
self.errorCallback = function() {};
|
||||
|
||||
self.items = [];
|
||||
|
||||
@@ -30,22 +30,22 @@ var NewsFetcher = function() {
|
||||
|
||||
var parser = new FeedMe();
|
||||
|
||||
parser.on('item', function(item) {
|
||||
parser.on("item", function(item) {
|
||||
self.items.push({
|
||||
title: item.title,
|
||||
pubdate: item.pubdate,
|
||||
});
|
||||
});
|
||||
|
||||
parser.on('end', function(item) {
|
||||
parser.on("end", function(item) {
|
||||
self.successCallback(self.items);
|
||||
});
|
||||
|
||||
parser.on('error', function(error) {
|
||||
parser.on("error", function(error) {
|
||||
self.errorCallback(error);
|
||||
});
|
||||
|
||||
request({uri:url, encoding:null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
request({uri: url, encoding: null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -5,21 +5,21 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var NodeHelper = require('node_helper');
|
||||
var validUrl = require('valid-url');
|
||||
var Fetcher = require('./fetcher.js');
|
||||
var NodeHelper = require("node_helper");
|
||||
var validUrl = require("valid-url");
|
||||
var Fetcher = require("./fetcher.js");
|
||||
|
||||
module.exports = NodeHelper.create({
|
||||
// Subclass start method.
|
||||
start: function() {
|
||||
console.log('Starting module: ' + this.name);
|
||||
console.log("Starting module: " + this.name);
|
||||
|
||||
this.fetchers = [];
|
||||
},
|
||||
|
||||
// Subclass socketNotificationReceived received.
|
||||
socketNotificationReceived: function(notification, payload) {
|
||||
if(notification === 'ADD_FEED') {
|
||||
if (notification === "ADD_FEED") {
|
||||
this.createFetcher(payload.url, payload.reloadInterval, payload.encoding);
|
||||
}
|
||||
},
|
||||
@@ -35,25 +35,25 @@ module.exports = NodeHelper.create({
|
||||
createFetcher: function(url, reloadInterval, encoding) {
|
||||
var self = this;
|
||||
|
||||
if (!validUrl.isUri(url)){
|
||||
self.sendSocketNotification('INCORRECT_URL', url);
|
||||
if (!validUrl.isUri(url)) {
|
||||
self.sendSocketNotification("INCORRECT_URL", url);
|
||||
return;
|
||||
}
|
||||
|
||||
var fetcher;
|
||||
if (typeof self.fetchers[url] === 'undefined') {
|
||||
console.log('Create new news fetcher for url: ' + url + ' - Interval: ' + reloadInterval);
|
||||
if (typeof self.fetchers[url] === "undefined") {
|
||||
console.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval);
|
||||
fetcher = new Fetcher(url, reloadInterval, encoding);
|
||||
|
||||
fetcher.onReceive(function(fetcher) {
|
||||
self.sendSocketNotification('NEWS_ITEMS', {
|
||||
self.sendSocketNotification("NEWS_ITEMS", {
|
||||
url: fetcher.url(),
|
||||
items: fetcher.items()
|
||||
});
|
||||
});
|
||||
|
||||
fetcher.onError(function(fetcher, error) {
|
||||
self.sendSocketNotification('FETCH_ERROR', {
|
||||
self.sendSocketNotification("FETCH_ERROR", {
|
||||
url: fetcher.url(),
|
||||
error: error
|
||||
});
|
||||
@@ -61,7 +61,7 @@ module.exports = NodeHelper.create({
|
||||
|
||||
self.fetchers[url] = fetcher;
|
||||
} else {
|
||||
console.log('Use exsisting news fetcher for url: ' + url);
|
||||
console.log("Use exsisting news fetcher for url: " + url);
|
||||
fetcher = self.fetchers[url];
|
||||
fetcher.setReloadInterval(reloadInterval);
|
||||
fetcher.broadcastItems();
|
||||
|
Reference in New Issue
Block a user