Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Only retrieve needed fields

Roland Geider277b8e1ff09f
diff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.py
index 2b852a18e..fb39eac9a 100644
--- a/wger/nutrition/sync.py
+++ b/wger/nutrition/sync.py
@@ -86,12 +86,17 @@ def fetch_image_from_wger_instance(ingredient):
def fetch_image_from_off(ingredient):
- # Everything looks fine, go ahead
+ """
+ See
+ - https://openfoodfacts.github.io/openfoodfacts-server/api/how-to-download-images/
+ - https://openfoodfacts.github.io/openfoodfacts-server/api/ref-v2/
+ """
logger.info(f'Trying to fetch image from OFF for {ingredient.name} (UUID: {ingredient.uuid})')
+
+ url = ingredient.source_url + '?fields=images,image_front_url'
headers = wger_headers()
+ product_data = requests.get(url, headers=headers).json()
- # Fetch the product data
- product_data = requests.get(ingredient.source_url, headers=headers).json()
image_url: Optional[str] = product_data['product'].get('image_front_url')
if not image_url:
logger.info('Product data has no "image_front_url" key')