From bc422512442718ca08202244d6dad9f7c3c202b0 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Wed, 13 Apr 2022 17:24:16 +0200 Subject: [PATCH] Added Digit Eyes service to get GTIN data --- asset/gtin_service.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/asset/gtin_service.py b/asset/gtin_service.py index 9fa1965..9d28179 100644 --- a/asset/gtin_service.py +++ b/asset/gtin_service.py @@ -24,9 +24,30 @@ def ask_upcitemdb_service(gtin): return product return None +def ask_digiteyes_service(gtin): + request = f'https://www.digit-eyes.com/gtin/v2_0/?upcCode={gtin}&field_names=all&language=en&app_key=%s&signature=%s' + response = requests.get(request) + if response.status_code == 200: + product_json = response.json() + print(f"Got {product_json['description']}") + if product_json['return_code'] == '0': + product = GtinProduct.objects.create(gtin=gtin, api_request=request, api_response=product_json) + if 'description' in product_json: + product.name = product_json['description'] + if 'brand' in product_json: + product.brand = product_json['brand'] + LOGGER.debug( + f"Creating new product entry for gtin={gtin}:\nrequest={request}\nresponse={response.status_code}:{product_json}") + product.save() + return product + return None + def ask_remote_services(gtin): product = ask_upcitemdb_service(gtin) + if product is not None: + return product + product = ask_digiteyes_service(gtin) if product is not None: return product return None