Browse Source

Configurable email address for user agent

master
Peetz0r 1 year ago
parent
commit
43281fd5b3
2 changed files with 4 additions and 3 deletions
  1. +1
    -0
      config.example.json
  2. +3
    -3
      get-barcode.js

+ 1
- 0
config.example.json View File

@ -2,6 +2,7 @@
"apiKeys": {
"eanData": "YOURKEYGOESHERE"
},
"email": "you@example.com",
"irc": {
"host": "irc.freenode.net",
"port": 6667,


+ 3
- 3
get-barcode.js View File

@ -1,13 +1,13 @@
"use strict";
const Promise = require("bluebird");
const bhttp = require("bhttp").session({ headers: { "user-agent": "barcodebot (problems: admin@cryto.net)" } });
const dotty = require("dotty");
const cheerio = require("cheerio");
const url = require("url");
const chalk = require("chalk");
const config = require("./config.json");
const bhttp = require("bhttp").session({ headers: { "user-agent": `barcodebot (problems: ${config.email})` } });
const parseFoodbook = require("./parse-foodbook");
function log(barcode, message) {
@ -157,7 +157,7 @@ function getBarcode_foodBook(barcode) {
function getBarcode_openFoodFacts(barcode) {
return Promise.try(() => {
log(barcode, "Trying OpenFoodFacts...");
return bhttp.get(`https://world.openfoodfacts.org/api/v0/product/${encodeURIComponent(barcode)}.json`);
}).then((response) => {
if (response.statusCode === 200 && response.body.status === 1 && response.body.product.product_name != null) {
@ -200,7 +200,7 @@ function getBarcode_buycott(barcode) {
} else {
productName = product;
}
return {
name: productName,
image: $(".header_image img").attr("src")


Loading…
Cancel
Save