Checking that file exists before checking size.

This commit is contained in:
Roland 2021-11-10 11:16:10 -07:00
parent 7a4524fc8f
commit 40f493ee68
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93

View file

@ -8,6 +8,7 @@ import gzip
import json
import logging
import os.path
import pathlib
import subprocess
import tempfile
@ -84,16 +85,15 @@ async def take_screenshot(url: str) -> bytes:
logger.error(f'Failed to screenshot {url}', exc_info=True)
return b''
try:
path = f'{tmp_dir}/screenshot.png'
size = os.path.getsize(path)
logger.info(f'Successful screenshot ({size} bytes) at {path}')
with open(path, 'rb') as fh:
png = fh.read()
return png
except FileNotFoundError:
path = pathlib.Path(f'{tmp_dir}/screenshot.png')
if not path.is_file():
return b''
size = os.path.getsize(path)
logger.info(f'Successful screenshot ({size} bytes) at {path}')
png = path.read_bytes()
return png
def prepare_bytes(b: bytes) -> str:
"""