Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions components/ecoindex/utils/screenshots.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import os

from ecoindex.models import ScreenShot
from PIL import Image

try:
from PIL import Image

_pillow_available = True
except ImportError:
_pillow_available = False


async def convert_screenshot_to_webp(screenshot: ScreenShot) -> None:
if not _pillow_available:
raise ImportError("Pillow is required for WebP conversion. Install it with: pip install ecoindex-scraper[webp]")
image = Image.open(rf"{screenshot.get_png()}")
width, height = image.size
ratio = 800 / height if width > height else 600 / width
Expand All @@ -17,7 +25,9 @@ async def convert_screenshot_to_webp(screenshot: ScreenShot) -> None:


async def set_screenshot_rights(
screenshot: ScreenShot, uid: int | None = None, gid: int | None = None
screenshot: ScreenShot,
uid: int | None = None,
gid: int | None = None,
) -> None:
if uid and gid:
os.chown(path=screenshot.get_webp(), uid=uid, gid=gid)
4 changes: 2 additions & 2 deletions projects/ecoindex_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ aiofile = "^3.8.8"
alembic = "^1.12.1"
celery = "^5.3.4"
fastapi = "^0.109.1"
pillow = "^12.0.0"
pillow = { version = "^12.2.0", optional = true }
playwright = "^1.39.0"
playwright-stealth = "^1.0.6"
pydantic = { version = ">=2.1.1,<=2.4.2", extras = ["email"] }
Expand All @@ -46,7 +46,7 @@ ua-generator = "^2.0.5"
uvicorn = "^0.23.2"

[tool.poetry.group.worker.dependencies]
pillow = "^12.0.0"
pillow = { version = "^12.2.0", optional = true }
playwright = "^1.39.0"
playwright-stealth = "^1.0.6"

Expand Down
5 changes: 4 additions & 1 deletion projects/ecoindex_scraper/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ pydantic = "^2.4.2"
python = "^3.10"
typing-extensions = "^4.8.0"
pyyaml = "^6.0.1"
pillow = ">=10.1,<13.0"
pillow = { version = "^12.2.0", optional = true }
setuptools = ">=69.5.1,<79.0.0"
ua-generator = "^2.0.5"

[tool.poetry.extras]
webp = ["pillow"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ setuptools = "^78.1.1"
cryptography = "^44.0.2"

[tool.poetry.group.scraper.dependencies]
pillow = "^12.0.0"
playwright = "^1.39.0"
playwright-stealth = "^1.0.6"

[tool.poetry.group.scraper-webp.dependencies]
pillow = { version = "^12.2.0", optional = true }

[tool.poetry.group.cli.dependencies]
click-spinner = "^0.1.10"
jinja2 = "^3.1.3"
Expand Down
Loading