Added OpenGTINdb service

This commit is contained in:
Dirk Jahnke 2022-04-13 18:00:27 +02:00
parent bc42251244
commit 04b3377df7
1 changed files with 23 additions and 0 deletions

View File

@ -42,12 +42,35 @@ def ask_digiteyes_service(gtin):
return product
return None
def ask_opengtindb_service(gtin):
request = f'http://opengtindb.org/?ean={gtin}&cmd=query&queryid=400000000'
response = requests.get(request)
if response.status_code == 200:
product_txt = response.text
print(f"Got {product_txt}")
if product_txt.startswith('error=0'):
product = GtinProduct.objects.create(gtin=gtin, api_request=request, api_response=product_txt)
product_props = product_txt.splitlines()
for prop in product_props:
if prop.startswith('name='):
product.name = prop[5:]
if prop.startswith('vendor='):
product.brand = prop[7:]
LOGGER.debug(
f"Creating new product entry for gtin={gtin}:\nrequest={request}\nresponse={response.status_code}:{product_txt}")
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
product = ask_opengtindb_service(gtin)
if product is not None:
return product
return None