Rinser/news.js

177 lines
4.1 KiB
JavaScript
Raw Normal View History

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 = {};
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 = {
"feed_name": "feed",
"default_count": 1,
"no_cdata_fields": [], // Don't wrap these fields in CDATA tags
"meta": {
"title": "News",
"description": "Combined News Feed",
'site_url': 'http://pipes.silvrtree.co.uk/news.xml'
},
"plugins": [
'filter_3_days', 'fix_images', 'fix_scripts'
],
"sources": [
{
"count": 100,
"feed_url": "http://qz.com/feed/"
},
{
"count": 100,
"feed_url": "http://feeds2.feedburner.com/businessinsider"
},
{
"count": 100,
"feed_url": "http://feeds.reuters.com/reuters/UKTopNews"
},
{
"count": 100,
"feed_url": "http://feeds.reuters.com/reuters/UKdomesticNews"
},
{
"count": 100,
"feed_url": "http://feeds.reuters.com/reuters/UKWorldNews"
},
{
"count": 100,
"feed_url": "http://feeds.reuters.com/reuters/topNews"
},
{
"count": 100,
"feed_url": "http://feeds.reuters.com/Reuters/worldNews"
2015-08-20 10:59:11 +00:00
}
,
{
"count": 100,
"feed_url": "http://feeds.reuters.com/reuters/globalmarketsNews"
},
{
"count": 100,
"feed_url": "http://hosted2.ap.org/atom/APDEFAULT/cae69a7523db45408eeb2b3a98c0c9c5"
},
{
"count": 100,
"feed_url": "http://www.cityam.com/feeds/main.xml"
},
{
"count": 100,
"feed_url": "http://www.londonlovesbusiness.com/navrss?navsectioncode=121"
},
{
"count": 100,
"feed_url": "http://www.ibtimes.co.uk/rss/uk"
},
{
"count": 100,
"feed_url": "http://feeds.bbci.co.uk/news/rss.xml?edition=uk"
},
{
"count": 100,
"feed_url": "http://feeds.bbci.co.uk/news/scotland/rss.xml?edition=uk"
},
{
"count": 100,
"feed_url": "http://news.google.com/?output=rss"
},
{
"count": 100,
"feed_url": "http://feeds.feedburner.com/TheAtlantic"
},
{
"count": 100,
"feed_url": "http://www.telegraph.co.uk/newsfeed/rss/news-uk_news.xml"
},
{
"count": 100,
"feed_url": "http://www.telegraph.co.uk/news/worldnews/rss"
},
{
"count": 100,
"feed_url": "http://www.guardian.co.uk/rssfeed/0,,1,00.xml"
},
{
"count": 100,
"feed_url": "http://www.marketwatch.com/rss/topstories"
},
{
"count": 100,
"feed_url": "http://feeds.feedburner.com/wingsoverscotland/FgKv"
},
{
"count": 100,
"feed_url": "http://bellacaledonia.org.uk/feed/"
2015-08-20 10:59:11 +00:00
}
,
{
"count": 100,
"feed_url": "http://www.theweek.co.uk/feeds/all"
}
2015-08-20 10:59:11 +00:00
]
}
;
2015-08-20 10:59:11 +00:00
var braider_options = {
feeds: feeds,
indent: " ",
date_sort_order: "desc", // Newest first
log_level: "warn",
dedupe_fields: ['link', 'guid'],
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
rss_braider.processFeed('simple_test_feed', 'json', function(err, data) {
console.log('A');
if (err) {
logger.error(err);
return err;
}
2015-08-20 10:59:11 +00:00
console.log('B');
2015-08-20 10:59:11 +00:00
var j = JSON.parse(data);
2015-08-20 10:59:11 +00:00
console.log('C');
var ejsOutput = ejs.compile(str)(j);
2015-08-20 10:59:11 +00:00
console.log('D');
fs.writeFile(__dirname + "/dist/" + outputFile + ".html",
ejsOutput,
function(err) {
2015-08-20 10:59:11 +00:00
if (err) {
logger.error(err);
return console.error(err);
}
2015-08-20 10:59:11 +00:00
console.log("The file was saved!");
2015-08-20 10:59:11 +00:00
});
fs.writeFile(__dirname + "/dist/" + outputFile + ".json",
data,
function(err) {
if (err) {
logger.error(err);
return console.error(err);
}
2015-08-20 10:59:11 +00:00
console.log("The file was saved!");
2015-08-20 10:59:11 +00:00
});
});