Files
old-kivi/crawler/crawl.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-11-10 13:04:45 +01:00
'use strict'
/*
Entry point for crawling functionality
All communication between crawlers and savers is here
All environment specific configuration is read here and
passed to the crawlers and savers.
*/
import {
install
} from 'source-map-support';
import 'dotenv/config';
import OlxCrawler from './specific/olx';
import MongoSaver from './savers/mongo'
install(); // for source maps to work
let crawlers = [
new OlxCrawler(process.env.OLX_FROM_PAGE, process.env.OLX_TO_PAGE, process.env.OLX_MAX_RESULTS)
];
let savers = [
new MongoSaver(process.env.MONGO_URL)
];
2016-11-10 14:03:58 +01:00
async function crawlAll() {
for (let crawler of crawlers) {
try {
let results = await crawler.crawl()
2016-11-10 13:04:45 +01:00
for (let saver of savers) {
try {
2016-11-10 14:03:58 +01:00
await saver.connect();
await saver.save(results);
2016-11-10 13:04:45 +01:00
} catch (e) {
console.log("Error saving. Trying next saver! ", e);
}
}
2016-11-10 14:03:58 +01:00
} catch (e) {
console.log("Error crawling. Trying next crawler! ", e);
}
2016-11-10 13:04:45 +01:00
}
2016-11-10 14:03:58 +01:00
for (let saver of savers) {
saver.close();
}
2016-11-10 13:04:45 +01:00
}
2016-11-10 14:03:58 +01:00
crawlAll();