import local image, download if fails.

This commit is contained in:
its_me_gb
2021-04-28 13:44:19 +01:00
parent 23415f8a61
commit 1bc5af1cab

View File

@@ -90,14 +90,21 @@ class RecetteTek(Integration):
# TODO: Parse Nutritional Information # TODO: Parse Nutritional Information
# Grab the original image that was used for the recipe # Import the original image from the zip file, if we cannot do that, attempt to download it again.
try: try:
if file['originalPicture']!= '': if file['pictures'][0] !='':
response = requests.get(file['originalPicture']) image_file_name = file['pictures'][0].split('/')[-1]
if imghdr.what(BytesIO(response.content)) != None: for f in self.files:
self.import_recipe_image(recipe, BytesIO(response.content)) if '.rtk' in f['name']:
else: import_zip = ZipFile(f['file'])
raise Exception("Original image failed to download.") self.import_recipe_image(recipe, BytesIO(import_zip.read(image_file_name)))
else:
if file['originalPicture'] != '':
response=requests.get(file['originalPicture'])
if imghdr.what(BytesIO(response.content)) != None:
self.import_recipe_image(recipe, BytesIO(response.content))
else:
raise Exception("Original image failed to download.")
except Exception as e: except Exception as e:
print(recipe.name, ': failed to import image ', str(e)) print(recipe.name, ': failed to import image ', str(e))