Browse Source

Configurable email address for user agent

pull/1/head
Peetz0r 2 years ago
parent
commit
43281fd5b3
  1. 1
      config.example.json
  2. 6
      get-barcode.js

1
config.example.json

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

6
get-barcode.js

@ -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