From 22aa81f2ee38fbbc311f7a77ca34f91abfc8138c Mon Sep 17 00:00:00 2001 From: Nick Leeman Date: Sat, 21 Nov 2020 13:29:45 +0100 Subject: [PATCH] added website support --- src/core.ts | 46 ++++++++++- src/modules/websites.ts | 170 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 1 deletion(-) diff --git a/src/core.ts b/src/core.ts index 5056102..9be5867 100644 --- a/src/core.ts +++ b/src/core.ts @@ -15,7 +15,18 @@ import { PerfectBody, Alternate, Expert, - Silvergear + Silvergear, + AlsaNature, + Dobey, + EzyDog, + K9Shop, + OnlineHondenSpeciaalZaak, + MacroVet, + PetDuka, + ZooEnzo, + PetsOnline, + PetsPlace, + ThePetEmpire } from "./modules/websites"; start(); @@ -197,6 +208,39 @@ async function crawlProductStock(url: string) { case "silvergear.eu": return [domain, page.url(), await Silvergear.check(html)]; + case "alsa-nature.nl": + return [domain, page.url(), await AlsaNature.check(html)]; + + case "dobey.nl": + return [domain, page.url(), await Dobey.check(html)]; + + case "ezydog.nl": + return [domain, page.url(), await EzyDog.check(html)]; + + case "k9shop.nl": + return [domain, page.url(), await K9Shop.check(html)]; + + case "onlinehondenspeciaalzaak.nl": + return [domain, page.url(), await OnlineHondenSpeciaalZaak.check(html)]; + + case "macrovet.nl": + return [domain, page.url(), await MacroVet.check(html)]; + + case "petduka.nl": + return [domain, page.url(), await PetDuka.check(html)]; + + case "petsonline.nl": + return [domain, page.url(), await PetsOnline.check(html)]; + + case "petsplace.nl": + return [domain, page.url(), await PetsPlace.check(html)]; + + case "zoo-enzo.nl": + return [domain, page.url(), await ZooEnzo.check(html)]; + + case "thepetempire.com": + return [domain, page.url(), await ThePetEmpire.check(html)]; + default: console.error(`-- ${domain} is not an available website module! Can't check stock!`); return [domain, page.url(), false]; diff --git a/src/modules/websites.ts b/src/modules/websites.ts index c9aceec..73f6c14 100644 --- a/src/modules/websites.ts +++ b/src/modules/websites.ts @@ -249,4 +249,174 @@ export namespace AlsaNature { return false; } } +} + +export namespace Dobey { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($("#product_view #stock_indicator").hasClass("stock_green")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace EzyDog { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($(".product-shop .availability").first().hasClass("in-stock")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace K9Shop { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($(".ty-qty-in-stock i").first().hasClass("ty-icon-ok")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace OnlineHondenSpeciaalZaak { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($("#Product #StockContainer #ShowOutOfStock").hasClass("hidden")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace MacroVet { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($(".row-products-blog .row-products-blog2 .active link").attr("href") == "http://schema.org/InStock") { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace PetDuka { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($("#product .hurry i").first().hasClass("icon-check-white")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace PetsOnline { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($("#content #product_configure_form .overlay-e i").first().hasClass("icon-check-circle")) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace PetsPlace { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($(".product-info-main #product-addtocart-button").length >= 1) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace ZooEnzo { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($(".row.main_content .availability .available-now link").attr("href") == "http://schema.org/InStock") { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } +} + +export namespace ThePetEmpire { + export async function check(html: string) { + try { + const $ = cheerio.load(html); + if ($("#content .form-product .add-to-cart-button").length >= 1) { + return true; + } else { + return false; + } + } catch (error) { + console.log(error); + console.error(`Error occured during stock check!`); + return false; + } + } } \ No newline at end of file