From 818132e8f13f0dee6513caa2035acbf1b0624d61 Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Sun, 29 Mar 2020 17:57:10 +0200 Subject: [PATCH] Calorielijst added as source --- get-barcode.js | 25 +++++++++++++++++++++++++ test.js | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/get-barcode.js b/get-barcode.js index 342c4b3..43a1f1e 100644 --- a/get-barcode.js +++ b/get-barcode.js @@ -37,6 +37,7 @@ let barcodeGetters = [ getBarcode_foodBook, getBarcode_eanData, getBarcode_openFoodFacts, + getBarcode_calorielijst, ]; module.exports = function getBarcode(barcode) { @@ -230,3 +231,27 @@ function getBarcode_bolCom(barcode) { } }); } + +function getBarcode_calorielijst(barcode) { + return Promise.try(() => { + log(barcode, "Trying calorielijst.nl..."); + + return bhttp.get(`http://www.calorielijst.nl/?search=${encodeURIComponent(barcode)}`); + }).then((response) => { + if (response.statusCode === 200) { + let $ = cheerio.load(response.body); + + let a = $(".calorienamediv a").first(); + let productName = cleanValue(a.text()); + + if (productName.length > 0) { + let image = a.data().id; + return { + name: productName, + image: (image != "") ? `http://img.calorielijst.nl/product/${image}` : null, + //~ price: "N/A", + }; + } + } + }); +} diff --git a/test.js b/test.js index 70cfc63..7f6ceba 100644 --- a/test.js +++ b/test.js @@ -5,7 +5,7 @@ const Promise = require("bluebird"); const getBarcode = require("./get-barcode"); Promise.try(() => { - return getBarcode("4002846034450"); + return getBarcode("8718265015388"); }).then((result) => { console.log(result); })