From 421c7b8e4baf524f08eec2a8dc384fe0306824cf Mon Sep 17 00:00:00 2001 From: martind2000 Date: Sat, 7 May 2016 09:55:35 +0100 Subject: [PATCH] added fivethirtyeight --- magazines.js | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 magazines.js diff --git a/magazines.js b/magazines.js new file mode 100644 index 0000000..2de7268 --- /dev/null +++ b/magazines.js @@ -0,0 +1,119 @@ +var outputFile = 'magazines', 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(); + +// 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": "Magazines", + "description": "Combined Magazines Feed", + 'site_url': 'http://pipes.silvrtree.co.uk/magazines.xml' + }, + "plugins": [ + + ], + "sources": [ + { + "count": 100, + "feed_url": "http://kat.cr/usearch/uk%20men%27s%20health%20category%3Abooks/?rss=1" + }, + { + "count": 100, + "feed_url": "http://kat.cr/usearch/uk%20men%27s%20fitness%20category%3Abooks/?rss=1" + }, + { + "count": 100, + "feed_url": "http://kat.cr/usearch/uk%20esquire%20category%3Abooks/?rss=1" + }, + { + "count": 100, + "feed_url": "http://kat.cr/usearch/uk%20muscle%20%26%20fitness%20category%3Abooks/?rss=1" + }, + { + "count": 100, + "feed_url": "http://kat.cr/usearch/men%27s%20journal%20category%3Abooks/?rss=1" + } + ] +} + +; +var braider_options = { + feeds: feeds, + indent: " ", + date_sort_order: "desc", // Newest first + log_level: "warn", + dedupe_fields: ['link', 'guid'], + plugins_directories: [__dirname + "/plugins/"] +}; +var rss_braider = RssBraider.createClient(braider_options); + +// Override logging level (debug, info, warn, err, off) +//rss_braider.logger.level('off'); + +rss_braider.processFeed('simple_test_feed', 'json', function(err, data) { + console.log('A'); + if (err) { + logger.error(err); + return err; + } + + console.log('B'); + + var j = JSON.parse(data); + + console.log('C'); + var ejsOutput = ejs.compile(str)(j); + + console.log('D'); + fs.writeFile(__dirname + "/dist/" + outputFile + ".html", + ejsOutput, + function(err) { + + if (err) { + logger.error(err); + return console.error(err); + } + + console.log("The file was saved!"); + }); + + fs.writeFile(__dirname + "/dist/" + outputFile + ".json", + data, + function(err) { + if (err) { + logger.error(err); + return console.error(err); + } + + console.log("The file was saved!"); + }); +}); + +rss_braider.processFeed('simple_test_feed', 'xml', function(err, data) { + console.log('A'); + if (err) { + logger.error(err); + return err; + } + + fs.writeFile(__dirname + "/dist/" + outputFile + ".xml", + data, + function(err) { + if (err) { + logger.error(err); + return console.error(err); + } + + console.log("The file was saved!"); + }); +});