Calorielijst added as source

pull/1/head
Peetz0r 4 years ago
parent 43281fd5b3
commit 818132e8f1

@ -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",
};
}
}
});
}

@ -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);
})

Loading…
Cancel
Save