|
|
@ -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) {
|
|
|
@ -157,7 +157,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 +200,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")
|
|
|
|