added website support!
This commit is contained in:
21
src/core.ts
21
src/core.ts
@@ -7,7 +7,11 @@ import { getDomain } from "tldts";
|
||||
// Import website modules
|
||||
import {
|
||||
FitnessKoerier,
|
||||
FitnessApparaat
|
||||
FitnessApparaat,
|
||||
BolCom,
|
||||
BeterSport,
|
||||
FitnessGeest,
|
||||
BodyAndFit
|
||||
} from "./modules/websites";
|
||||
|
||||
start();
|
||||
@@ -94,6 +98,9 @@ async function crawlBlogPage(url: string) {
|
||||
allProducts.push(products[index]);
|
||||
}
|
||||
|
||||
console.log("");
|
||||
console.log("");
|
||||
|
||||
} catch (error) {
|
||||
console.log("Error while trying to crawl page! Skipping...");
|
||||
}
|
||||
@@ -118,11 +125,23 @@ async function crawlProductStock(url: string) {
|
||||
await page.close();
|
||||
|
||||
switch (domain) {
|
||||
case "bol.com":
|
||||
return [domain, page.url(), await BolCom.check(html)];
|
||||
|
||||
case "fitnesskoerier.nl":
|
||||
return [domain, page.url(), await FitnessKoerier.check(html)];
|
||||
|
||||
case "fitnessapparaat.nl":
|
||||
return [domain, page.url(), await FitnessApparaat.check(html)];
|
||||
|
||||
case "betersport.nl":
|
||||
return [domain, page.url(), await BeterSport.check(html)];
|
||||
|
||||
case "fitness-geest.nl":
|
||||
return [domain, page.url(), await FitnessGeest.check(html)];
|
||||
|
||||
case "bodyandfit.com":
|
||||
return [domain, page.url(), await BodyAndFit.check(html)];
|
||||
|
||||
default:
|
||||
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
|
||||
|
@@ -48,4 +48,82 @@ export namespace FitnessApparaat {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace BolCom {
|
||||
export async function check(html: string) {
|
||||
try {
|
||||
const $ = cheerio.load(html);
|
||||
if ($('[data-test="outofstock-buy-block"]').length >= 1) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(`Error occured during stock check!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace BeterSport {
|
||||
export async function check(html: string) {
|
||||
try {
|
||||
const $ = cheerio.load(html);
|
||||
if ($('.product-shop .in-stock').first().html() !== null) {
|
||||
if ($('.product-shop .in-stock').first().html().trim() == "Niet op voorraad, neem contact op voor actuele informatie") {
|
||||
return false;
|
||||
}
|
||||
|
||||
else if ($('.product-shop .in-stock').first().html().trim().includes("week")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(`Error occured during stock check!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace FitnessGeest {
|
||||
export async function check(html: string) {
|
||||
try {
|
||||
const $ = cheerio.load(html);
|
||||
if ($('.product-info-box .in_stock_message').length >= 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(`Error occured during stock check!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace BodyAndFit {
|
||||
export async function check(html: string) {
|
||||
try {
|
||||
const $ = cheerio.load(html);
|
||||
if ($('.product-page .product-cart-controls .btn__primary').first().attr("disabled")) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(`Error occured during stock check!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user