Working RSS Feed Manager
- Auto updates feeds - Sends updates to specified channels - Needs threading
This commit is contained in:
26
controllers/rssController.js
Normal file
26
controllers/rssController.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//Will handle updating feeds in all channels
|
||||||
|
|
||||||
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||||
|
const log = new DebugBuilder("server", "rssController");
|
||||||
|
|
||||||
|
const libCore = require("../libCore");
|
||||||
|
const libUtils = require("../libUtils");
|
||||||
|
|
||||||
|
exports.RSSController = class RSSController {
|
||||||
|
constructor(_client) {
|
||||||
|
this.client = _client;
|
||||||
|
}
|
||||||
|
|
||||||
|
async start(){
|
||||||
|
log.INFO("Starting RSS Controller");
|
||||||
|
while(true){
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 10000));
|
||||||
|
this.collectLatestPosts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async collectLatestPosts(){
|
||||||
|
log.INFO("Updating sources");
|
||||||
|
libCore.updateFeeds(this.client)
|
||||||
|
}
|
||||||
|
}
|
||||||
6
index.js
6
index.js
@@ -8,6 +8,7 @@ var http = require('http');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const libCore = require("./libCore");
|
const libCore = require("./libCore");
|
||||||
|
const { RSSController } = require("./controllers/rssController");
|
||||||
const libUtils = require("./libUtils");
|
const libUtils = require("./libUtils");
|
||||||
const deployCommands = require("./utilities/deployCommands");
|
const deployCommands = require("./utilities/deployCommands");
|
||||||
|
|
||||||
@@ -123,8 +124,9 @@ client.on('ready', () => {
|
|||||||
log.DEBUG(`Starting HTTP Server`);
|
log.DEBUG(`Starting HTTP Server`);
|
||||||
runHTTPServer();
|
runHTTPServer();
|
||||||
|
|
||||||
log.DEBUG("Loading new posts");
|
log.DEBUG("Loading new posts");
|
||||||
libCore.updateFeeds(client);
|
const rssManager = new RSSController(client);
|
||||||
|
rssManager.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup any additional event handlers
|
// Setup any additional event handlers
|
||||||
|
|||||||
23
libCore.js
23
libCore.js
@@ -2,7 +2,7 @@
|
|||||||
let Parser = require('rss-parser');
|
let Parser = require('rss-parser');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
let parser = new Parser();
|
let parser = new Parser();
|
||||||
const storageHandler = require("./libStorage");
|
const { FeedStorage, PostStorage } = require("./libStorage");
|
||||||
const libUtils = require("./libUtils");
|
const libUtils = require("./libUtils");
|
||||||
const { createHash } = require("crypto");
|
const { createHash } = require("crypto");
|
||||||
|
|
||||||
@@ -19,15 +19,9 @@ const configuration = new Configuration({
|
|||||||
|
|
||||||
const openai = new OpenAIApi(configuration);
|
const openai = new OpenAIApi(configuration);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Data Structures
|
|
||||||
var feeds = {};
|
|
||||||
var rssFeedMap = [];
|
|
||||||
var rssFeedCategories = [];
|
|
||||||
|
|
||||||
// Setup Storage handlers
|
// Setup Storage handlers
|
||||||
var feedStorage = new storageHandler.feedStorage();
|
var feedStorage = new FeedStorage();
|
||||||
var postStorage = new storageHandler.postStorage();
|
var postStorage = new PostStorage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or updates new source url to configured storage
|
* Adds or updates new source url to configured storage
|
||||||
@@ -291,7 +285,10 @@ exports.getChat = async function (_prompt, { _model = "text-davinci-003", _tempe
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
exports.getSources = function () {
|
exports.getSources = function () {
|
||||||
return feeds;
|
feedStorage.getAllRecords((err, records) => {
|
||||||
|
if (err) throw err;
|
||||||
|
return records;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -320,7 +317,11 @@ exports.getQuotes = async function (quote_url) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
exports.getCategories = function () {
|
exports.getCategories = function () {
|
||||||
return rssFeedCategories;
|
feedStorage.getUniqueByKey("category", (err, results) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
return results
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.addPost = (postObject, callback) => {
|
exports.addPost = (postObject, callback) => {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.feedStorage = class feedStorage extends Storage {
|
exports.FeedStorage = class FeedStorage extends Storage {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(rssFeedsTable);
|
super(rssFeedsTable);
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ exports.feedStorage = class feedStorage extends Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.postStorage = class postStorage extends Storage {
|
exports.PostStorage = class PostStorage extends Storage {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(rssPostsTable);
|
super(rssPostsTable);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user