mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Checking that file exists before checking size.
This commit is contained in:
parent
7a4524fc8f
commit
40f493ee68
1 changed files with 8 additions and 8 deletions
|
|
@ -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:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue