Files
old-web/app/services/crawlerService.js

69 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-06-13 15:49:31 +02:00
// import OlxCrawler from '../helpers/crawlers/olixClawler'
const OlxCrawler = require("../helpers/crawlers/olxClawler");
2019-06-20 14:51:14 +02:00
const db = require("../models/index");
const MarketAlert = require("../models/marketalert");
2019-06-13 15:49:31 +02:00
const crawlers = [
2019-06-20 21:27:51 +02:00
new OlxCrawler(1, 2, 3),
// new OlxCrawler(process.env.OLX_FROM_PAGE, process.env.OLX_TO_PAGE, process.env.OLX_MAX_RESULTS),
];
2019-06-13 15:49:31 +02:00
2019-06-20 21:27:51 +02:00
async function crawlAll() {
const properties = db.MarketAlert.rawAttributes;
console.log(properties);
for (let crawler of crawlers) {
try {
let results = await crawler.crawl();
const marketAlerts = [];
for (const result of results) {
console.log("This is result", result);
console.log("This is result", result.size);
// category: category,
// url,
// title,
// price: isNaN(parsedPrice) ? price : parsedPrice,
// size: parseFloat(size),
// rooms: parsedRooms,
// floor: parseInt(floor),
// address,
// location,
// // adType: AD_TYPE_SALE,
// time,
// shortDescription: descriptions.first().text(),
// longDescription: descriptions.last().text(),
// lat,
// lng,
// loc: [parseFloat(lat), parseFloat(lng)],
marketAlerts.push({
url: result.url,
realestateOrigin: "OLX",
originId: "1",
size: "" + result.size,
price: result.price,
email: "em"
// lastDate: DataTypes.STRING,
// municipailty: DataTypes.STRING,
// region: DataTypes.STRING,
// gardenSize: DataTypes.INTEGER,
})
}
2019-06-13 15:49:31 +02:00
try {
2019-06-20 21:27:51 +02:00
await db.MarketAlert.bulkCreate(marketAlerts);
2019-06-13 15:49:31 +02:00
} catch (e) {
2019-06-20 21:27:51 +02:00
console.log("Could not bulkCreate marketalers reason: ", e);
2019-06-13 15:49:31 +02:00
}
2019-06-20 21:27:51 +02:00
} catch (e) {
console.log("Error crawling. Trying next crawler! ", e);
2019-06-13 15:49:31 +02:00
}
}
2019-06-20 21:27:51 +02:00
}
crawlAll();