screenshot: change ouptut file path, append site name

This commit is contained in:
Corentin Sechet 2022-04-11 13:40:58 +02:00
parent fc3b44b620
commit 936248c3ce
1 changed files with 6 additions and 6 deletions

View File

@ -42,7 +42,7 @@ async def screenshot_diff(
async with right_source.get_browser(
width=width, height=height
) as right_browser:
urls = [(theme, url) for (theme, site) in config.sites for url in site.urls]
urls = [(site_name, url) for (site_name, site) in config.sites for url in site.urls]
await report_progress(
"Screenshoting",
@ -50,16 +50,16 @@ async def screenshot_diff(
(
url,
_diff_url(
left_browser, right_browser, url, output_path / theme
left_browser, right_browser, url, output_path, site_name
),
)
for (theme, url) in urls
for (site_name, url) in urls
],
nb_workers=3,
)
async def _diff_url(left: Browser, right: Browser, url: str, output_path: Path) -> None:
async def _diff_url(left: Browser, right: Browser, url: str, output_path: Path, site_name: str) -> None:
try:
left_bytes = await _screenshot_url(left, url)
right_bytes = await _screenshot_url(right, url)
@ -81,10 +81,10 @@ async def _diff_url(left: Browser, right: Browser, url: str, output_path: Path)
if not output_path.is_dir():
output_path.mkdir()
with open(output_path / f"{url_slug}_left", "wb") as screenshot_file:
with open(output_path / f"{site_name}_{url_slug}_left", "wb") as screenshot_file:
screenshot_file.write(left_bytes)
with open(output_path / f"{url_slug}_right", "wb") as screenshot_file:
with open(output_path / f"{site_name}_{url_slug}_right", "wb") as screenshot_file:
screenshot_file.write(right_bytes)
except Exception as ex:
print(f"Error while diffing {url} : {ex}")