added support for fotodevakman.nl

This commit is contained in:
Nick Leeman 2021-03-26 16:45:37 +01:00
parent 52317d4211
commit 7ff8b26a61
2 changed files with 34 additions and 2 deletions

View File

@ -35,7 +35,8 @@ import {
WifiMedia,
Ep,
Kinq,
Maxiaxi
Maxiaxi,
FotoDeVakman
} from "./modules/websites";
// Globals
@ -49,7 +50,7 @@ start();
async function debugStart() {
browser = await puppeteer.launch({ headless: false });
console.log(await crawlProductStock("https://www.maxiaxi.com/complete-lichtset-met-jelly-ball-laser-en-rookmachine/"));
console.log(await crawlProductStock("https://www.fotodevakman.nl/sony-a7-iii-body-sony-sel-sel-28-60mm-f4-5-6"));
}
async function start() {
@ -295,6 +296,9 @@ async function crawlProductStock(url: string) {
case "maxiaxi.com":
return [domain, page.url(), await Maxiaxi.check(html)];
case "fotodevakman.nl":
return [domain, page.url(), await FotoDeVakman.check(html)];
default:
console.error(`-- ${domain} is not an available website module! Can't check stock!`);

View File

@ -584,6 +584,34 @@ export namespace Maxiaxi {
}
});
return stock;
} catch (error) {
console.log(error);
console.error(`Error occured during stock check!`);
return false;
}
}
}
export namespace FotoDeVakman {
export async function check(html: string) {
try {
const $ = cheerio.load(html);
let stock = false;
$('script[type="application/ld+json"]').each((index, element) => {
let json = JSON.parse($(element).html());
if (json["@type"]) {
if (json["@type"] == "Product") {
if (json["offers"]["availability"] == "http://schema.org/InStock") {
stock = true;
return;
}
}
}
});
return stock;
} catch (error) {
console.log(error);