-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (45 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require('fs');
const express = require('express');
const app = express();
const ScraperManager = require('./scraper_manager');
const Feed = require('./feed');
const userConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
//var serveStatic = require('serve-static');
// app.use(serveStatic('public/'))
const scraperManager = new ScraperManager(userConfig['scrapers']);
function initFeeds (config) {
const feeds = [];
for (let i = 0; i < config.length; i++) {
const node = config[i];
const routeName = node['route'] || '/feed/rss';
const feed = new Feed(node['title'], routeName, node['scrapers'].map((name) => scraperManager.getScraper(name)));
feeds.push(feed);
app.get(routeName, function (req, res) {
res.set('Content-Type', 'text/xml');
return res.render('rss', {
feed: {
title: feed.getName()
},
items: feed.get()
});
});
console.log(`Feed ${feed.getName()} created. Check it out: http://127.0.0.1:${userConfig['port']}${feed.getRoute()}`);
}
return feeds;
}
scraperManager.initialize().then(() => {
console.log('INIT: scrappers');
initFeeds(userConfig['feeds']);
console.log('INIT: feeds');
});
app.listen(userConfig['port']);
const updateInterval = userConfig['updateInterval'] * 1000;
setInterval(() => {
if (!scraperManager.ready()) {
return;
}
console.log('Updating...');
scraperManager.update();
}, updateInterval);