mirror of
https://github.com/karl0ss/JDRssDownloader.git
synced 2025-04-27 20:03:40 +01:00
28 lines
857 B
JavaScript
28 lines
857 B
JavaScript
const fs = require("fs");
|
|
const Parser = require("rss-parser");
|
|
const lodash = require('lodash');
|
|
|
|
async function feedUpdater() {
|
|
// Make a new RSS Parser
|
|
const parser = new Parser();
|
|
|
|
// Get all the items in the RSS feed
|
|
const feed = await parser.parseURL(JSON.parse(fs.readFileSync('config.json')).RSSFeed);
|
|
|
|
let items = [];
|
|
|
|
if (fs.existsSync('./feedCache.json')) {
|
|
items = JSON.parse(fs.readFileSync('./feedCache.json'))
|
|
}
|
|
// Compare existing cache and new items and merge differences
|
|
let updatedArray = lodash.unionBy(feed.items, items, 'title');
|
|
|
|
// Save the file
|
|
log.info(updatedArray.length + ' items in file cache')
|
|
fs.writeFileSync('./feedCache.json', JSON.stringify(updatedArray));
|
|
global.rss_refresh_time = new Date();
|
|
}
|
|
|
|
module.exports = {
|
|
feedUpdater
|
|
} |