2016-04-18 12:49:38 +00:00
|
|
|
var outputFile = 'news', RssBraider = require('rss-braider'), fs = require('fs'), ejs = require(
|
|
|
|
'ejs'), read = require('fs').readFileSync, join = require('path').join, str = read(
|
|
|
|
join(__dirname, '/templates/rss.ejs'),
|
|
|
|
'utf8'), feeds = {};
|
|
|
|
|
2017-02-07 22:10:31 +00:00
|
|
|
var argv = require('yargs').argv;
|
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
var log4js = require('log4js');
|
|
|
|
var logger = log4js.getLogger();
|
2015-08-20 10:59:11 +00:00
|
|
|
|
|
|
|
// Pull feeds from config files: ,
|
|
|
|
// feeds.simple_test_feed = require("./config/feed").feed;
|
|
|
|
// Or define in-line
|
|
|
|
|
|
|
|
feeds.simple_test_feed = {
|
2017-10-01 17:25:17 +00:00
|
|
|
'feed_name': 'feed',
|
|
|
|
'default_count': 1,
|
|
|
|
'no_cdata_fields': ['description'], // Don't wrap these fields in CDATA tags
|
|
|
|
'meta': {
|
|
|
|
'title': 'News',
|
|
|
|
'description': 'Combined News Feed',
|
2016-04-18 12:49:38 +00:00
|
|
|
'site_url': 'http://pipes.silvrtree.co.uk/news.xml'
|
|
|
|
},
|
2017-10-01 17:25:17 +00:00
|
|
|
'plugins': [
|
2016-04-18 12:49:38 +00:00
|
|
|
'filter_3_days', 'fix_images', 'fix_scripts'
|
|
|
|
],
|
2017-10-01 17:25:17 +00:00
|
|
|
'custom_namespaces': {
|
|
|
|
'content': 'http://purl.org/rss/1.0/modules/content/',
|
|
|
|
'slash': 'http://purl.org/rss/1.0/modules/slash/',
|
|
|
|
'media': 'http://search.yahoo.com/mrss/',
|
|
|
|
'ev': 'http://purl.org/rss/2.0/modules/event/',
|
|
|
|
'sy': 'http://purl.org/rss/1.0/modules/syndication/',
|
|
|
|
'wfw': 'http://wellformedweb.org/CommentAPI/',
|
|
|
|
'dc': 'http://purl.org/dc/elements/1.1/',
|
|
|
|
'atom': 'http://www.w3.org/2005/Atom'
|
|
|
|
},
|
2018-03-04 16:39:52 +00:00
|
|
|
'sources': [{'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fqz.com%2Ffeed%2F'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds2.feedburner.com%2Fbusinessinsider'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUKTopNews'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUKdomesticNews'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUKWorldNews'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FtopNews'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.reuters.com%2FReuters%2FworldNews'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fhosted2.ap.org%2Fatom%2FAPDEFAULT%2Fcae69a7523db45408eeb2b3a98c0c9c5'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.cityam.com%2Ffeeds%2Fmain.xml'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.londonlovesbusiness.com%2Fnavrss%3Fnavsectioncode%3D121'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.ibtimes.co.uk%2Frss%2Fuk'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Frss.xml%3Fedition%3Duk'
|
2017-10-01 17:25:17 +00:00
|
|
|
}, {
|
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Fscotland%2Frss.xml%3Fedition%3Duk'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fnews.google.com%2F%3Foutput%3Drss'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.feedburner.com%2FTheAtlantic'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.telegraph.co.uk%2Fnews%2Frss.xml'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.guardian.co.uk%2Frssfeed%2F0%2C%2C1%2C00.xml'
|
2018-05-16 09:13:08 +00:00
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.marketwatch.com%2Fmarketwatch%2Ftopstories%2F'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffeeds.feedburner.com%2Fwingsoverscotland%2FFgKv'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fbellacaledonia.org.uk%2Ffeed%2F'}, {
|
2017-10-01 17:25:17 +00:00
|
|
|
'count': 100,
|
2018-03-04 16:39:52 +00:00
|
|
|
'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Fwww.theweek.co.uk%2Ffeeds%2Fall'
|
|
|
|
}, {'count': 100, 'feed_url': 'http://45.33.114.116:8080/http%3A%2F%2Ffivethirtyeight.com%2Fall%2Ffeed'}]
|
2016-04-18 12:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
;
|
2015-08-20 10:59:11 +00:00
|
|
|
var braider_options = {
|
2016-04-18 12:49:38 +00:00
|
|
|
feeds: feeds,
|
2017-10-01 17:25:17 +00:00
|
|
|
indent: ' ',
|
|
|
|
date_sort_order: 'desc', // Newest first
|
|
|
|
log_level: 'warn',
|
2016-04-18 12:49:38 +00:00
|
|
|
dedupe_fields: ['link', 'guid'],
|
2017-10-01 17:25:17 +00:00
|
|
|
plugins_directories: [__dirname + '/plugins/']
|
2015-08-20 10:59:11 +00:00
|
|
|
};
|
|
|
|
var rss_braider = RssBraider.createClient(braider_options);
|
|
|
|
|
|
|
|
// Override logging level (debug, info, warn, err, off)
|
2016-02-12 13:10:16 +00:00
|
|
|
//rss_braider.logger.level('off');
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2017-10-01 17:25:17 +00:00
|
|
|
rss_braider.processFeed('simple_test_feed', 'json', function (err, data) {
|
2016-04-18 12:49:38 +00:00
|
|
|
console.log('A');
|
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return err;
|
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
console.log('B');
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
var j = JSON.parse(data);
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
console.log('C');
|
|
|
|
var ejsOutput = ejs.compile(str)(j);
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
console.log('D');
|
2017-10-01 17:25:17 +00:00
|
|
|
fs.writeFile(__dirname + '/dist/' + outputFile + '.html',
|
2016-04-18 12:49:38 +00:00
|
|
|
ejsOutput,
|
2017-10-01 17:25:17 +00:00
|
|
|
function (err) {
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2016-04-18 12:49:38 +00:00
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return console.error(err);
|
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2017-10-01 17:25:17 +00:00
|
|
|
console.log('The file was saved!');
|
2015-08-20 10:59:11 +00:00
|
|
|
});
|
|
|
|
|
2017-10-01 17:25:17 +00:00
|
|
|
fs.writeFile(__dirname + '/dist/' + outputFile + '.json',
|
2016-04-18 12:49:38 +00:00
|
|
|
data,
|
2017-10-01 17:25:17 +00:00
|
|
|
function (err) {
|
2016-04-18 12:49:38 +00:00
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return console.error(err);
|
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2017-10-01 17:25:17 +00:00
|
|
|
console.log('The file was saved!');
|
2015-08-20 10:59:11 +00:00
|
|
|
});
|
2016-04-18 12:49:38 +00:00
|
|
|
});
|