Notification screenshot/JPEG was not being regenerated correctly (#1149)

pull/1158/head
dgtlmoon 2 years ago committed by GitHub
parent 68d5178367
commit ce6c2737a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -252,20 +252,11 @@ class model(dict):
return None
def get_screenshot_as_jpeg(self):
"""Best used in notifications due to its smaller size"""
png_fname = os.path.join(self.watch_data_dir, "last-screenshot.png")
jpg_fname = os.path.join(self.watch_data_dir, "last-screenshot.jpg")
if os.path.isfile(jpg_fname):
return jpg_fname
if os.path.isfile(png_fname) and not os.path.isfile(jpg_fname):
# Doesnt exist, so create the JPEG from the PNG
from PIL import Image
im1 = Image.open(png_fname)
im1.convert('RGB').save(jpg_fname, quality=int(os.getenv("NOTIFICATION_SCREENSHOT_JPG_QUALITY", 75)))
return jpg_fname
# Created by save_screenshot()
fname = os.path.join(self.watch_data_dir, "last-screenshot.jpg")
if os.path.isfile(fname):
return fname
# False is not an option for AppRise, must be type None
return None

@ -368,6 +368,12 @@ class ChangeDetectionStore:
f.write(screenshot)
f.close()
# Make a JPEG that's used in notifications (due to being a smaller size) available
from PIL import Image
im1 = Image.open(target_path)
im1.convert('RGB').save(target_path.replace('.png','.jpg'), quality=int(os.getenv("NOTIFICATION_SCREENSHOT_JPG_QUALITY", 75)))
def save_error_text(self, watch_uuid, contents):
if not self.data['watching'].get(watch_uuid):
return

@ -71,13 +71,18 @@ def test_check_notification(client, live_server):
time.sleep(3)
# We write the PNG to disk, but a JPEG should appear in the notification
testimage_png = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
# Write the last screenshot png
testimage_png = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
# This one is created when we save the screenshot from the webdriver/playwright session (converted from PNG)
testimage_jpg = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/wAALCAABAAEBAREA/8QAFAABAAAAAAAAAAAAAAAAAAAACf/EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAD8AKp//2Q=='
uuid = extract_UUID_from_client(client)
datastore = 'test-datastore'
with open(os.path.join(datastore, str(uuid), 'last-screenshot.png'), 'wb') as f:
f.write(base64.b64decode(testimage_png))
with open(os.path.join(datastore, str(uuid), 'last-screenshot.jpg'), 'wb') as f:
f.write(base64.b64decode(testimage_jpg))
# Goto the edit page, add our ignore text
# Add our URL to the import page
@ -128,8 +133,6 @@ def test_check_notification(client, live_server):
time.sleep(3)
set_modified_response()
notification_submission = None
# Trigger a check
client.get(url_for("form_watch_checknow"), follow_redirects=True)
time.sleep(3)

Loading…
Cancel
Save