Added Digit Eyes service to get GTIN data

This commit is contained in:
Dirk Jahnke 2022-04-13 17:24:16 +02:00
parent e74fa36128
commit bc42251244
1 changed files with 21 additions and 0 deletions

View File

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