added wifimedia support

This commit is contained in:
Nick Leeman 2021-03-26 15:24:00 +01:00
parent 8e52c437ef
commit e8d271edc6
2 changed files with 23 additions and 1 deletions

View File

@ -31,7 +31,8 @@ import {
Conrad,
HuisdierExpress,
HondenBed,
Coolblue
Coolblue,
WifiMedia
} from "./modules/websites";
// Globals
@ -280,6 +281,9 @@ async function crawlProductStock(url: string) {
case "hondenbed.nl":
return [domain, page.url(), await HondenBed.check(html)];
case "wifimedia.eu":
return [domain, page.url(), await WifiMedia.check(html)];
default:
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
return [domain, page.url(), false];

View File

@ -509,3 +509,21 @@ export namespace Coolblue {
}
}
export namespace WifiMedia {
export async function check(html: string) {
try {
const $ = cheerio.load(html);
if ($("[itemprop=availability]").first().attr("content") == "http://schema.org/InStock") {
return true;
}
return false;
} catch (error) {
console.log(error);
console.error(`Error occured during stock check!`);
return false;
}
}
}