|
|
@ -1,13 +1,13 @@
|
|
|
|
"use strict";
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
const bhttp = require("bhttp").session({ headers: { "user-agent": "barcodebot (problems: admin@cryto.net)" } });
|
|
|
|
|
|
|
|
const dotty = require("dotty");
|
|
|
|
const dotty = require("dotty");
|
|
|
|
const cheerio = require("cheerio");
|
|
|
|
const cheerio = require("cheerio");
|
|
|
|
const url = require("url");
|
|
|
|
const url = require("url");
|
|
|
|
const chalk = require("chalk");
|
|
|
|
const chalk = require("chalk");
|
|
|
|
|
|
|
|
|
|
|
|
const config = require("./config.json");
|
|
|
|
const config = require("./config.json");
|
|
|
|
|
|
|
|
const bhttp = require("bhttp").session({ headers: { "user-agent": `barcodebot (problems: ${config.email})` } });
|
|
|
|
const parseFoodbook = require("./parse-foodbook");
|
|
|
|
const parseFoodbook = require("./parse-foodbook");
|
|
|
|
|
|
|
|
|
|
|
|
function log(barcode, message) {
|
|
|
|
function log(barcode, message) {
|
|
|
@ -37,6 +37,7 @@ let barcodeGetters = [
|
|
|
|
getBarcode_foodBook,
|
|
|
|
getBarcode_foodBook,
|
|
|
|
getBarcode_eanData,
|
|
|
|
getBarcode_eanData,
|
|
|
|
getBarcode_openFoodFacts,
|
|
|
|
getBarcode_openFoodFacts,
|
|
|
|
|
|
|
|
getBarcode_calorielijst,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function getBarcode(barcode) {
|
|
|
|
module.exports = function getBarcode(barcode) {
|
|
|
@ -157,7 +158,7 @@ function getBarcode_foodBook(barcode) {
|
|
|
|
function getBarcode_openFoodFacts(barcode) {
|
|
|
|
function getBarcode_openFoodFacts(barcode) {
|
|
|
|
return Promise.try(() => {
|
|
|
|
return Promise.try(() => {
|
|
|
|
log(barcode, "Trying OpenFoodFacts...");
|
|
|
|
log(barcode, "Trying OpenFoodFacts...");
|
|
|
|
|
|
|
|
|
|
|
|
return bhttp.get(`https://world.openfoodfacts.org/api/v0/product/${encodeURIComponent(barcode)}.json`);
|
|
|
|
return bhttp.get(`https://world.openfoodfacts.org/api/v0/product/${encodeURIComponent(barcode)}.json`);
|
|
|
|
}).then((response) => {
|
|
|
|
}).then((response) => {
|
|
|
|
if (response.statusCode === 200 && response.body.status === 1 && response.body.product.product_name != null) {
|
|
|
|
if (response.statusCode === 200 && response.body.status === 1 && response.body.product.product_name != null) {
|
|
|
@ -200,7 +201,7 @@ function getBarcode_buycott(barcode) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
productName = product;
|
|
|
|
productName = product;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
name: productName,
|
|
|
|
name: productName,
|
|
|
|
image: $(".header_image img").attr("src")
|
|
|
|
image: $(".header_image img").attr("src")
|
|
|
@ -218,13 +219,36 @@ function getBarcode_bolCom(barcode) {
|
|
|
|
if (response.statusCode === 200) {
|
|
|
|
if (response.statusCode === 200) {
|
|
|
|
let $ = cheerio.load(response.body);
|
|
|
|
let $ = cheerio.load(response.body);
|
|
|
|
|
|
|
|
|
|
|
|
let productName = cleanValue($(".pdp-header__title").text());
|
|
|
|
let productName = cleanValue($(".product-title").text());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (productName.length > 0) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
name: productName,
|
|
|
|
|
|
|
|
image: $(".product-image img").attr("src").replace("/regular/", "/extralarge/"),
|
|
|
|
|
|
|
|
price: `€ ${cleanValue($("meta[itemprop=price]").attr('content')).replace(".", ",")}`,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (productName.length > 0) {
|
|
|
|
|
|
|
|
let image = a.data().id;
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
name: productName,
|
|
|
|
name: productName,
|
|
|
|
image: $(".js_product_img").attr("src"),
|
|
|
|
image: (image != "") ? `http://img.calorielijst.nl/product/${image}` : null,
|
|
|
|
price: `€ ${cleanValue($(".promo-price").text())}`
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|