Basic nutrition editor (#288)

* Basic nutrition editor

* fix no image on scrape

* nutrition display

* add recipe images

* update by url

* new upload options

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-04-11 13:16:33 -08:00
committed by GitHub
parent 2a158ab290
commit 406dae6e97
10 changed files with 234 additions and 29 deletions

View File

@@ -62,12 +62,16 @@ def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path:
extension = extension.replace(".", "")
image_path = image_dir.joinpath(f"original.{extension}")
if isinstance(file_data, bytes):
if isinstance(file_data, Path):
shutil.copy2(file_data, image_path)
elif isinstance(file_data, bytes):
with open(image_path, "ab") as f:
f.write(file_data)
else:
shutil.copy2(file_data, image_path)
with open(image_path, "ab") as f:
shutil.copyfileobj(file_data, f)
print(image_path)
minify.minify_image(image_path)
return image_path
@@ -105,7 +109,7 @@ def scrape_image(image_url: str, slug: str) -> Path:
write_image(slug, r.raw, filename.suffix)
filename.unlink()
filename.unlink(missing_ok=True)
return slug