bottemplates/store-server.gbai/store-server.gbdialog/scan-barcode.bas

31 lines
800 B
QBasic
Raw Normal View History

PARAM image AS STRING
barcode = SCAN BARCODE image
IF NOT barcode THEN
RETURN {error: "No barcode found"}
END IF
ean = barcode.data
cached = FIND "products", "global_trade_number=" + ean
IF cached THEN
RETURN cached
END IF
data = GET "https://world.openfoodfacts.org/api/v0/product/" + ean + ".json"
IF data.product THEN
product = {
name: data.product.product_name,
brand: data.product.brands,
global_trade_number: ean,
description: data.product.generic_name,
category: data.product.categories,
net_weight: data.product.quantity
}
ELSE
product = LLM "Search product info for EAN: " + ean + ". Return JSON {name, brand, description, category}"
product.global_trade_number = ean
END IF
SAVE "products", product
RETURN product