adds cron job for scraping
This commit is contained in:
23
index.js
23
index.js
@@ -1,6 +1,7 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const server = express();
|
const server = express();
|
||||||
|
const schedule = require('node-schedule');
|
||||||
const { connect } = require('./lib/repository');
|
const { connect } = require('./lib/repository');
|
||||||
const thepiratebayScraper = require('./scrapers/thepiratebay/thepiratebay_scraper');
|
const thepiratebayScraper = require('./scrapers/thepiratebay/thepiratebay_scraper');
|
||||||
const horribleSubsScraper = require('./scrapers/horriblesubs/horriblesubs_scraper');
|
const horribleSubsScraper = require('./scrapers/horriblesubs/horriblesubs_scraper');
|
||||||
@@ -10,30 +11,28 @@ const rarbgScraper = require('./scrapers/rarbg/rarbg_scraper');
|
|||||||
const thepiratebayDumpScraper = require('./scrapers/thepiratebay/thepiratebay_dump_scraper');
|
const thepiratebayDumpScraper = require('./scrapers/thepiratebay/thepiratebay_dump_scraper');
|
||||||
const thepiratebayUnofficialDumpScraper = require('./scrapers/thepiratebay/thepiratebay_unofficial_dump_scraper');
|
const thepiratebayUnofficialDumpScraper = require('./scrapers/thepiratebay/thepiratebay_unofficial_dump_scraper');
|
||||||
|
|
||||||
const providers = [
|
const PROVIDERS = [
|
||||||
// horribleSubsScraper,
|
horribleSubsScraper,
|
||||||
rarbgScraper,
|
rarbgScraper,
|
||||||
// thepiratebayScraper,
|
thepiratebayScraper,
|
||||||
// kickassScraper,
|
kickassScraper,
|
||||||
// leetxScraper
|
leetxScraper
|
||||||
];
|
];
|
||||||
|
const SCRAPE_CRON = process.env.SCRAPE_CRON || '* 0/4 * * * *';
|
||||||
|
|
||||||
async function scrape() {
|
async function scrape() {
|
||||||
return providers
|
return PROVIDERS
|
||||||
.reduce((promise, scrapper) => promise.then(() => scrapper.scrape()), Promise.resolve());
|
.reduce((promise, scrapper) => promise
|
||||||
|
.then(() => scrapper.scrape().catch(() => Promise.resolve())), Promise.resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
server.get('/', function (req, res) {
|
server.get('/', function (req, res) {
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.post('/scrape', function (req, res) {
|
|
||||||
scrape();
|
|
||||||
res.send(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(process.env.PORT || 7000, async function () {
|
server.listen(process.env.PORT || 7000, async function () {
|
||||||
await connect();
|
await connect();
|
||||||
|
schedule.scheduleJob(SCRAPE_CRON, () => scrape());
|
||||||
console.log('Scraper started');
|
console.log('Scraper started');
|
||||||
scrape();
|
scrape();
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user