added bored

This commit is contained in:
Martin Donnelly 2018-06-18 23:30:26 +01:00
parent 93a7a019ee
commit 04425993f2

View File

@ -42,6 +42,31 @@ const rss_braider = RssBraider.createClient(braider_options);
// Override logging level (debug, info, warn, err, off) // Override logging level (debug, info, warn, err, off)
//rss_braider.logger.level('off'); //rss_braider.logger.level('off');
function gatherV2(feedName, fileName, mode) {
const modeSuffix = {'rss': '.xml', 'json': '.json'};
return new Promise((resolve, reject) => {
logger.info(`Gathering ${feedName}...`);
rss_braider.processFeed(feedName, mode, function (err, data) {
if (err) {
logger.error(err);
return reject(err);
}
fs.writeFile(`${__dirname}/dist/${fileName}${modeSuffix[mode]}`,
data,
function (err) {
if (err) {
logger.error(err);
return reject(err);
}
return resolve(`${feedName} saved`);
});
});
});
}
async function gather(feedName, fileName) { async function gather(feedName, fileName) {
logger.info(`Gathering ${feedName}...`); logger.info(`Gathering ${feedName}...`);
rss_braider.processFeed(feedName, 'json', function (err, data) { rss_braider.processFeed(feedName, 'json', function (err, data) {
@ -86,34 +111,59 @@ async function gather(feedName, fileName) {
} }
async function gatherXML(feedName, fileName) { async function gatherXML(feedName, fileName) {
rss_braider.processFeed(feedName, 'rss', function(err, data) { rss_braider.processFeed(feedName, 'rss', function (err, data) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
console.log('Saving', __dirname + "/dist/" + fileName + ".xml"); console.log('Saving', __dirname + '/dist/' + fileName + '.xml');
fs.writeFile(__dirname + "/dist/" + fileName + ".xml", data, function(err) { fs.writeFile(__dirname + '/dist/' + fileName + '.xml', data, function (err) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
console.log("The file was saved!"); console.log('The file was saved!');
}); });
}); });
} }
async function main() { async function main() {
await gatherXML('jobsSpecial','jobs-special').then((d) => { await gatherV2('jobsSpecial', 'jobs-special', 'rss').then((d) => {
logger.info('### jobsSpecial done.') logger.info(d);
}).catch((e) => {
logger.error(e);
}); });
await gather('news', 'news'); await gatherV2('news', 'news', 'json').then((d) => {
await gather('lifestyle', 'lifestyle'); logger.info(d);
}).catch((e) => {
await gather('paleo', 'paleo'); logger.error(e);
await gather('tech', 'tech'); });
await gather('fit', 'fit'); await gatherV2('lifestyle', 'lifestyle', 'json').then((d) => {
await gather('bored', 'bored'); logger.info(d);
// await gatherXML('jobsLocal','jobs-local'); }).catch((e) => {
logger.error(e);
});
await gatherV2('paleo', 'paleo', 'json').then((d) => {
logger.info(d);
}).catch((e) => {
logger.error(e);
});
await gatherV2('tech', 'tech', 'json').then((d) => {
logger.info(d);
}).catch((e) => {
logger.error(e);
});
await gatherV2('fit', 'fit', 'json').then((d) => {
logger.info(d);
}).catch((e) => {
logger.error(e);
});
await gatherV2('bored', 'bored', 'json').then((d) => {
logger.info(d);
}).catch((e) => {
logger.error(e);
});
// await gatherXML('jobsLocal','jobs-local');
} }